# @eggjs/eventbus-plugin

> tegg event plugin

Latest version **4.1.0** (published 2026-10-07) · 0 weekly downloads

## Install

```sh
npm install @eggjs/eventbus-plugin
pnpm add @eggjs/eventbus-plugin
yarn add @eggjs/eventbus-plugin
bun add @eggjs/eventbus-plugin
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.1.0 |
| Published | 2026-10-07 |
| First published | 2025-10-23 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=22.18.0 |
| Dependencies | 7 |
| Unpacked size | 14.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| Maintainers | gxkl, eggjs-admin, fengmk2, atian25, hyj1991, killagu, coolme200, akitasummer, elrrrrrrr, niania |
| Keywords | decorator, egg, eventbus, tegg, typescript |

## Links

- npm: https://www.npmjs.com/package/@eggjs/eventbus-plugin
- Repository: https://github.com/eggjs/egg
- Homepage: https://github.com/eggjs/egg/tree/next/tegg/plugin/eventbus
- Issues: https://github.com/eggjs/egg/issues
- npm.io page: https://npm.io/package/@eggjs/eventbus-plugin

## Dependencies (7)

- [@eggjs/metadata](https://npm.io/package/@eggjs/metadata.md) 4.1.0
- [@eggjs/lifecycle](https://npm.io/package/@eggjs/lifecycle.md) 4.1.0
- [@eggjs/tegg-runtime](https://npm.io/package/@eggjs/tegg-runtime.md) 4.1.0
- [@eggjs/module-common](https://npm.io/package/@eggjs/module-common.md) 4.1.0
- [@eggjs/core-decorator](https://npm.io/package/@eggjs/core-decorator.md) 4.1.0
- [@eggjs/eventbus-runtime](https://npm.io/package/@eggjs/eventbus-runtime.md) 4.1.0
- [@eggjs/eventbus-decorator](https://npm.io/package/@eggjs/eventbus-decorator.md) 4.1.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 4.1.0 (latest) — 2026-10-07
- 4.0.2-rc.1 (rc) — 2026-10-06
- 4.0.2-beta.27 (beta) — 2026-09-20
- 4.0.2 — 2026-10-06
- 4.0.2-rc.0 — 2026-09-23
- 4.0.2-beta.26 — 2026-08-07
- 4.0.2-beta.25 — 2026-07-13
- 4.0.2-beta.24 — 2026-07-12
- 4.0.2-beta.23 — 2026-07-11
- 4.0.2-beta.22 — 2026-07-11
- 4.0.2-beta.20 — 2026-07-09
- 4.0.2-beta.19 — 2026-06-29
- 4.0.2-beta.17 — 2026-06-28
- 4.0.2-beta.16 — 2026-06-26
- 4.0.2-beta.15 — 2026-06-26
- … 24 more at https://npm.io/package/@eggjs/eventbus-plugin/versions

## README

# @eggjs/eventbus-plugin

[![NPM version][npm-image]][npm-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]
[![Node.js Version](https://img.shields.io/node/v/@eggjs/eventbus-plugin.svg?style=flat)](https://nodejs.org/en/download/)

[npm-image]: https://img.shields.io/npm/v/@eggjs/eventbus-plugin.svg?style=flat-square
[npm-url]: https://npmjs.org/package/@eggjs/eventbus-plugin
[snyk-image]: https://snyk.io/test/npm/@eggjs/eventbus-plugin/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/@eggjs/eventbus-plugin
[download-image]: https://img.shields.io/npm/dm/@eggjs/eventbus-plugin.svg?style=flat-square
[download-url]: https://npmjs.org/package/@eggjs/eventbus-plugin

## Usage

```js
// plugin.js
export.teggEventbus = {
  enable: true,
  package: '@eggjs/eventbus-plugin',
};
```

## Unittest

```ts
// test/fixtures/apps/event-app/app/event-module/HelloService
@ContextProto({
  accessLevel: AccessLevel.PUBLIC,
})
export class HelloService {
  @Inject()
  private readonly eventBus: EventBus;

  hello() {
    this.eventBus.emit('hello', '01');
  }
}

// test/fixtures/apps/event-app/app/event-module/HelloLogger
@Event('helloEgg')
export class HelloLogger {
  handle(msg: string) {
    console.log('hello, ', msg);
  }
}

// test/event.test.ts
import assert from 'assert';
import path from 'path';
import mm from 'egg-mock';
import { HelloService } from './fixtures/apps/event-app/app/event-module/HelloService';
import { HelloLogger } from './fixtures/apps/event-app/app/event-module/HelloLogger';

describe('test/eventbus.test.ts', () => {
  let app;
  let ctx;

  afterEach(async () => {
    await app.destroyModuleContext(ctx);
    mm.restore();
  });

  before(async () => {
    app = mm.app();
    await app.ready();
  });

  after(() => {
    return app.close();
  });

  it('msg should work', async () => {
    ctx = await app.mockModuleContext();
    const helloService = await ctx.getEggObject(HelloService);
    let msg: string | undefined;
    // helloLogger is in child context, should mock the prototype
    mm(HelloLogger.prototype, 'handle', (m) => {
      msg = m;
    });
    const eventWaiter = await app.getEventWaiter();
    const helloEvent = eventWaiter.await('hello');
    helloService.hello();
    await helloEvent;
    assert(msg === '01');
  });
});
```

---
_Source: https://npm.io/package/@eggjs/eventbus-plugin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
