Skip to main content
The Courier Node.js SDK gives typed, server-side access to the Courier REST API from TypeScript or JavaScript. Available on GitHub and npm.

Installation

Requires Node.js 20+ (LTS), TypeScript 4.9+. Also works in Deno 1.28+, Bun 1.0+, Cloudflare Workers, and Vercel Edge Runtime.

Quick start

The client reads COURIER_API_KEY from your environment.
Building in a framework? The Next.js transactional email, Express, and Node.js daily digest quickstarts put this client into a working app.

Authentication

Get your API key from Platform → API Keys in the Courier dashboard. Set it as an environment variable:
The SDK reads it by default. To pass the key explicitly:

Sending notifications

With a template

Design your notification in Design Studio, then reference it by ID:

To multiple recipients

Send to several recipients in one call:

Available resources

The SDK covers the full Courier API.

Common operations

Checking message status

After sending, use the requestId to check delivery status or get the full event timeline:
List recent messages with optional filters:

Managing user profiles

Profiles store the recipient data Courier delivers to: email, phone, and custom fields. Create the profile before sending to a user_id.
create merges with any existing profile. replace overwrites it and drops any field you leave out.

Issuing JWT tokens

Courier’s client-side SDKs (React, JavaScript, mobile) authenticate users with a JWT your backend issues. Authenticate users covers the token flow, the scope strings, and token refresh. Use auth.issueToken:
The scope string controls what the token can access. Common scopes:

TypeScript types

Every request and response has a TypeScript definition. Import them directly:
Methods, parameters, and response fields carry docstrings that show on hover in VS Code and other editors.

Configuration

Error handling

The SDK throws typed errors for API failures. All errors extend Courier.APIError:

Retries

The SDK retries failed requests up to 2 times with exponential backoff. It retries connection failures, 408, 409, 429, and 5xx responses.

Timeouts

Requests time out after 60 seconds by default. Configure globally or per-request:
A timeout throws APIConnectionTimeoutError. The SDK retries timed-out requests by default.

Logging

Enable debug logging with the COURIER_LOG environment variable or the logLevel client option:
At debug level the SDK logs every HTTP request and response, headers and bodies included. You can also pass a custom logger (pino, winston, etc.):

Raw response access

Access HTTP headers or the underlying Response object:

Journeys

Journeys are multi-step workflows: send, delay, branch, throttle, digest, and more. Invoke one by ID or alias to start a run. Cancel runs by ID, or by a shared cancelation token.
cancel takes exactly one of run_id or cancelation_token (spelled with one “l”). Build and manage journeys from code with client.journeys.create, list, publish, and archive. See Build journeys via API.

More operations

A few more resources from the full Courier REST API:

API Reference

Full REST API docs with request/response examples.

Send API

Learn about the Send endpoint, routing, and message options.

Quickstart

Send your first notification in under two minutes.

GitHub

Source code, issues, and changelog.

Idempotent sends

Pass an idempotency key and Courier replays the first response for that key instead of sending again. The SDK sets the Idempotency-Key header for you. Idempotency covers the scoping rule and the replay window.