# @nextcloud/event-bus

> A simple event bus to communicate between Nextcloud components.

Latest version **3.3.3** (published 2025-11-07) · GPL-3.0-or-later license · 0 weekly downloads

## Install

```sh
npm install @nextcloud/event-bus
pnpm add @nextcloud/event-bus
yarn add @nextcloud/event-bus
bun add @nextcloud/event-bus
```

## Health

**Score 65/100 (B)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.3.3 |
| Published | 2025-11-07 |
| First published | 2019-10-04 |
| Weekly downloads | 0 |
| License | GPL-3.0-or-later |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | ^20 \|\| ^22 \|\| ^24 |
| Dependencies | 2 |
| Unpacked size | 31.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Nextcloud GmbH and Nextcloud contributors |
| Maintainers | icewind1991, skjnldsv, christophwurst, juliushaertl, nickvergessen, artonge, gretadoci, mejo-, susnux |
| Keywords | nextcloud |

## Links

- npm: https://www.npmjs.com/package/@nextcloud/event-bus
- Repository: https://github.com/nextcloud/nextcloud-event-bus
- Homepage: https://github.com/nextcloud/nextcloud-event-bus#readme
- Issues: https://github.com/nextcloud/nextcloud-event-bus/issues
- npm.io page: https://npm.io/package/@nextcloud/event-bus

## Dependencies (2)

- [semver](https://npm.io/package/semver.md) ^7.7.2
- [@types/semver](https://npm.io/package/@types/semver.md) ^7.7.0

## Recent versions

- 3.3.3 (latest) — 2025-11-07
- 3.3.2 — 2025-02-28
- 3.3.1 — 2024-05-27
- 3.3.0 — 2024-05-15
- 3.2.0 — 2024-04-21
- 3.1.0 — 2023-05-17
- 3.0.2 — 2022-09-06
- 3.0.1 — 2022-09-01
- 3.0.0 — 2022-08-11
- 2.1.1 — 2021-11-02
- 2.1.0 — 2021-09-28
- 2.0.0 — 2021-05-05
- 1.3.0 — 2021-05-05
- 1.2.0 — 2020-06-03
- 1.1.4 — 2020-04-06
- … 7 more at https://npm.io/package/@nextcloud/event-bus/versions

## README

<!--
  - SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  - SPDX-License-Identifier: CC0-1.0
-->

# @nextcloud/event-bus

[![REUSE status](https://api.reuse.software/badge/github.com/nextcloud-libraries/nextcloud-event-bus)](https://api.reuse.software/info/github.com/nextcloud-libraries/nextcloud-event-bus)
[![Build Status](https://img.shields.io/github/actions/workflow/status/nextcloud/nextcloud-event-bus/node.yml?branch=master)](https://github.com/nextcloud/nextcloud-event-bus/actions/workflows/node.yml?query=branch%3Amaster) [![Code coverage](https://img.shields.io/codecov/c/gh/nextcloud/nextcloud-event-bus/master)](https://app.codecov.io/gh/nextcloud/nextcloud-event-bus) [![npm](https://img.shields.io/npm/v/@nextcloud/event-bus.svg)](https://www.npmjs.com/package/@nextcloud/event-bus)
[![Documentation](https://img.shields.io/badge/Documentation-online-brightgreen)](https://nextcloud.github.io/nextcloud-event-bus/)

A simple event bus to communicate between Nextcloud components.

## Installation

```sh
npm install @nextcloud/event-bus --save
```

```sh
yarn add @nextcloud/event-bus
```

## Usage

```js
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'

const h = (e) => console.info(e)

subscribe('a', h)
subscribe('b', h)

emit('a', {
	data: 123,
})

unsubscribe('a', h)
unsubscribe('b', h)
```

### Typed events

It is also possible to type events, which allows type infering on the event-bus methods like `emit`, `subscribe` and `unsubscribe`.
To register new events, simply extend the `NextcloudEvents` interface:

1. Create a file like `event-bus.d.ts`:

```ts
declare module '@nextcloud/event-bus' {
	interface NextcloudEvents {
		'example-app:awesomeness:increased': { level: number }
	}
}

export {}
```

2. Now if you use any of the event bus functions, the parameters will automatically be typed correctly:

```ts
import { subscribe } from '@nextcloud/event-bus'

subscribe('example-app:awesomeness:increased', (event) => {
	// "event" automatically infers type { level: number}
	console.log(event.level)
})
```

## Naming convention

To stay consistent, we encourage you to use the following syntax when declaring events

`app-id:object:verb`

### Examples:

- `nextcloud:unified-search:closed`
- `files:node:uploading`
- `files:node:uploaded`
- `files:node:deleted`
- `contacts:contact:deleted`
- `calendar:event:created`
- `forms:answer:updated`

## Development

```sh
npm install

npm run build
npm run test
```

### Requirements

- [Node 20 or higher](https://nodejs.org/en/download/)
- [NPM 10 or higher](https://www.npmjs.com/package/npm)

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