Installation

This SDK is the server half of your integration. Your users read and write feeds from your app with a client SDK, and anything that needs a connected user or a live WebSocket belongs there: the state layer, device push registration, and client-side error handling. See the client-side overview for what lives there. Token signing stays on this side, because it needs your API secret.

npm install @stream-io/node-sdk
// or using yarn
yarn add @stream-io/node-sdk

GitHub repository: https://github.com/GetStream/stream-node. Feel free to submit bug reports and feature requests.

The package is tested against these environments:

  • Node.js@18
  • Node.js@20
  • Node.js@22
  • Bun@1

Node@16 is not supported.

The package can be used with both JavaScript and TypeScript.

To create a server-side client, you'll need your API key and secret. Both of them can be found in your Stream Dashboard.

You can optionally pass a timeout for the API requests, the default timeout is 3000ms. The shared defaults and tuning options are documented on Connection pooling; the timeout option and the custom agent below are the Node specifics.

import { StreamClient } from "@stream-io/node-sdk";
// or
// const { StreamClient } = require("@stream-io/node-sdk");

const apiKey = "";
const secret = "";
client = new StreamClient(apiKey, secret);

// optionally add timeout to API requests
// the default timeout is 3000ms
client = new StreamClient(apiKey, secret, { timeout: 3000 });

Custom HTTP agent

The SDK uses the built-in fetch. To control connection pooling and keep-alive, pass a custom undici Agent as the agent option; it is used as the dispatcher for all requests:

import { StreamClient } from "@stream-io/node-sdk";
import { Agent } from "undici";

const agent = new Agent({
  connections: 10, // max connections per origin
  keepAliveTimeout: 55_000, // idle socket timeout in ms
});

const client = new StreamClient(apiKey, secret, { timeout: 3000, agent });