---
source_url: https://www.pubnub.com/docs/serverless-sdk/modules-and-libraries/pubnub
title: pubnub
updated_at: 2026-09-30T07:20:08.000Z
---

# pubnub

## Documentation index

To discover more PubNub resources:

1. Fetch [PubNub's llms.txt](https://www.pubnub.com/llms-full.txt) for a list of available pages in Markdown format.
2. Identify relevant URLs from that index.
3. Fetch the target pages.

Do not assume a path exists, always check the index first.

The `pubnub` built-in module is available only inside a PubNub Function. It provides PubNub client SDK capabilities and Functions-specific publishing methods.

```javascript
const pubnub = require('pubnub');
```

Full parameter and response documentation for each capability lives on its own canonical page:

| Capability | Representative methods | Canonical reference |
| --- | --- | --- |
| Pub/Sub | `publish()`, `fire()`, `signal()` | [Publish overview](https://www.pubnub.com/docs/pub-sub/publish/overview.md). Also documented in full [below](#publish-fire-and-signal) |
| Access Manager | `grantToken()`, `parseToken()` | [Access control overview](https://www.pubnub.com/docs/security/access-control/overview.md) |
| Presence | `hereNow()`, `whereNow()`, `setState()`, `getState()` | [Presence overview](https://www.pubnub.com/docs/presence/overview.md) |
| Channel Groups | `addChannels()`, `listChannels()`, `removeChannels()`, `deleteGroup()` | [Channel Groups API reference](https://www.pubnub.com/docs/sdks/rest-api/channel-groups-introduction.md) |
| Message Persistence | `history()`, `fetchMessages()`, `deleteMessages()`, `messageCounts()` | [Message history overview](https://www.pubnub.com/docs/data-storage/message-history/overview.md) |
| App Context | `objects.*` methods | [Metadata overview](https://www.pubnub.com/docs/data-storage/metadata/overview.md) |
| Message Actions | `addMessageAction()` and related methods | [Message actions overview](https://www.pubnub.com/docs/pub-sub/message-actions/overview.md) |
| Mobile Push | `push.addChannels()` and related methods | [Mobile Push API reference](https://www.pubnub.com/docs/sdks/rest-api/mobile-push-notifications-introduction.md) |
| File Sharing | `listFiles()`, `getFileUrl()`, `publishFile()` | [Files overview](https://www.pubnub.com/docs/data-storage/files/overview.md) |

The legacy `grant()` (Access Manager v2) method is out of scope. `grantToken()` supersedes it.

File Sharing methods from the `pubnub` module cover file metadata operations only. Uploading and downloading file content requires a [PubNub client SDK](https://www.pubnub.com/docs/sdks.md). A Function cannot perform the transfer itself.

The following capabilities are Functions-specific and are not documented elsewhere.

## Publish, fire, and signal

`publish({message, channel})` sends a message to subscribers and Functions. `fire({message, channel})` triggers Functions without delivering to subscribers.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| message | Object | Yes |  | The message to send. |
| channel | String | Yes |  | The channel to publish to. |

Both return a Promise. The published or fired payload must be valid JSON. A string payload doesn't trigger Functions.

```javascript
const pubnub = require('pubnub');
pubnub.publish({
    channel: 'hello_universe',
    message: request.message
}).then((publishResponse) => {
    console.log(`Publish Status: ${publishResponse[0]}:${publishResponse[1]} with TT ${publishResponse[2]}`);
});
```

`signal({message, channel})` sends a [signal](https://www.pubnub.com/docs/architecture/core-concepts.md#message) to subscribers and Functions.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| message | Object | Yes |  | The signal payload. |
| channel | String | Yes |  | The channel to signal on. |

Returns a Promise. Signal payloads are limited to 64 bytes. The payload must also be valid JSON. A string payload doesn't trigger Functions.

```javascript
const pubnub = require('pubnub');
pubnub.signal({
    channel: 'hello_universe',
    message: request.message
}).then((signalResponse) => {
    console.log(`Signal Status: ${signalResponse[0]}:${signalResponse[1]} with TT ${signalResponse[2]}`);
});
```

Functions support chaining up to 3 hops, so a Function can trigger at most two more Functions downstream. Trigger each hop using `publish()`, `fire()`, or `signal()`.

## Related reference

* [Modules and libraries](https://www.pubnub.com/docs/serverless-sdk/modules-and-libraries/overview.md). Every built-in module available inside a Function.
* [Function types](https://www.pubnub.com/docs/serverless-sdk/function-types.md). Per-trigger reference for every Function type.
* [API limits](https://www.pubnub.com/docs/serverless-sdk/api-limits.md). Per-execution operation caps, including PubNub API calls and chain depth.

Last updated at: 2026-09-30T07:20:08.000Z
