# Events (/sdks/nodejs/reference/events)



Publish with `sendEvent` and consume through `subscribeToEvents`, passing strongly typed subscription options.

## sendEvent [#sendevent]

```typescript
await client.sendEvent(message: EventMessage): Promise<void>
```

**Parameters:**

| Name      | Type           | Required | Description                   |
| --------- | -------------- | -------- | ----------------------------- |
| `message` | `EventMessage` | Yes      | Channel, body, metadata, tags |

**Returns:** `Promise<void>` — resolves when the broker accepts the message.

## subscribeToEvents [#subscribetoevents]

```typescript
client.subscribeToEvents(subscription: EventsSubscription): Subscription
```

**EventsSubscription:**

| Field     | Type              | Required | Description      |
| --------- | ----------------- | -------- | ---------------- |
| `channel` | `string`          | Yes      | Channel name     |
| `group`   | `string`          | No       | Consumer group   |
| `onEvent` | `(event) => void` | Yes      | Delivery handler |
| `onError` | `(err) => void`   | Yes      | Error handler    |

**Returns:** `Subscription` — call `cancel()` to stop.

## Quick Usage [#quick-usage]

```typescript title="events.ts"
await client.sendEvent(
  createEventMessage({ channel: "events.demo", body: Buffer.from("hello") }),
);
```

## See Also [#see-also]

* [Events Examples](/sdks/nodejs/how-to/events/)
* [Events pattern](/learn/events/getting-started)
* [Node.js SDK Getting Started](/sdks/nodejs)
