# Migrate Node.js from Pusher: keep the pusher package, change the host

> Move an Express, Fastify, NestJS or serverless backend off Pusher Channels: one constructor change, auth and webhook handlers that stay, and a switch without a gap.

Source: https://hibira.io/topics/migrate-from-pusher-nodejs
Updated: 2026-11-18

Node.js backends on Pusher Channels publish with the `pusher` package from Express, Fastify, NestJS, workers or serverless functions. That package takes a `host` option, so moving to a Pusher-compatible service changes one constructor and the environment behind it. Your triggers, auth handler and webhook handler stay as they are, and so does pusher-js in your web or React Native app.

## What changes and what stays

| Part of your app | Changes? | What to do |
| --- | --- | --- |
| `trigger()` and `triggerBatch()` | No | Nothing |
| Auth handler with `authorizeChannel()` and `authenticateUser()` | No | Nothing; the signatures are the same |
| Channel queries with `pusher.get()` | No | Nothing |
| `new Pusher({...})` | Yes | Replace `cluster` with `host` |
| pusher-js clients | Yes | Add `wsHost` and the new key |
| Allowed origins | New | List your domains on the app; the Free plan needs exact origins |

## Step 1: the client

```js
import Pusher from 'pusher';

export const pusher = new Pusher({
  appId: process.env.PUSHER_APP_ID,
  key: process.env.PUSHER_APP_KEY,
  secret: process.env.PUSHER_APP_SECRET,
  host: process.env.PUSHER_HOST ?? 'ws.hibira.io',
  useTLS: true,
});

await pusher.trigger('orders', 'order-shipped', { id: 1024 });
await pusher.triggerBatch([
  { channel: 'orders', name: 'order-shipped', data: { id: 1024 } },
  { channel: 'private-user-7', name: 'notice', data: { text: 'Shipped' } },
]);
```

A batch holds up to 10 events. The options are in the [pusher-http-node README](https://github.com/pusher/pusher-http-node), checked on 2026-11-18.

## Step 2: auth and webhooks in Express

```js
app.post('/pusher/auth', express.urlencoded({ extended: false }), requireUser, (req, res) => {
  const { socket_id, channel_name } = req.body;
  if (channel_name.startsWith('presence-')) {
    return res.json(pusher.authorizeChannel(socket_id, channel_name, { user_id: req.user.id, user_info: { name: req.user.name } }));
  }
  res.json(pusher.authorizeChannel(socket_id, channel_name));
});

app.post('/pusher/webhooks', express.raw({ type: 'application/json' }), (req, res) => {
  const webhook = pusher.webhook({ headers: req.headers, rawBody: req.body.toString('utf8') });
  if (!webhook.isValid()) return res.sendStatus(401);
  for (const e of webhook.getEvents()) console.log(e.name, e.channel);
  res.sendStatus(200);
});
```

The webhook route must read the raw body: a JSON body parser that runs first changes the bytes and the signature no longer matches.

## Step 3: the clients

pusher-js in the browser and in React Native takes the same options:

```js
const client = new Pusher(PUSHER_KEY, {
  cluster: 'mt1',
  wsHost: 'ws.hibira.io',
  wsPort: 443,
  wssPort: 443,
  forceTLS: true,
  enabledTransports: ['ws', 'wss'],
  channelAuthorization: { endpoint: '/pusher/auth', transport: 'ajax' },
});
```

## Step 4: switch without a gap

Keep a second `Pusher` client with the old credentials and publish to both for a day or two, while clients update. Remove it when Pusher's dashboard shows no more connections, and add your webhook URL on the new app.

## More for Node.js

The [Node.js guide](https://hibira.io/guides/node) has the setup on one page, and the [NestJS package](https://hibira.io/guides/nestjs) adds a global module with decorators for channel authorization and webhooks. The [WebSocket tester](https://hibira.io/tools/websocket-tester) connects from your browser to check a key, host and channel before you deploy.

## Questions

### Do I have to change my package?

No. The official `pusher` package works with a `host` option, and so does the official pusher-js client. Nothing else needs installing.

### Does it work in AWS Lambda or other serverless functions?

Yes. Each trigger is an HTTPS request, so it works anywhere Node.js can make one. Await the promise before the function returns, or the request may be cut off.

### What happens to events published during the switch?

If you publish to both services, every client gets each event once, from whichever service it is connected to. Without that, clients still on Pusher miss events sent only to the new service until they reload.

### Are channel and event names limited the same way?

Yes. Channel names are up to 164 characters, and the same prefixes decide the channel type. Event data is a string that usually holds JSON, as on Pusher.
