first-send.mts, then run it with your API key and email address:
courier-node-digest-quickstart
The finished Node.js app from this guide, ready to clone and run.
Build this with a coding agent
To have a coding agent add Courier to your Node.js app, paste this prompt into Claude Code, Cursor, or Codex from the project root:npx skills add trycourier/courier-skills, and connect the Courier MCP server so the agent can check Courier Logs and templates itself.
Rules for AI agents
- Use
@trycourier/courierthrough the client inlib/courier.ts, not raw HTTP. - Read
COURIER_API_KEYfrom the environment on the server. Never send it to a browser or commit.env. - Invoke the journey once per comment, with an
Idempotency-Keybuilt from the comment’s database id:comment-<id>. - Invoke from the route that saves the comment, after it commits. The Batch node, not your code, decides when to send.
- Change the journey or template in
scripts/setup.tsand rerunnpm run setup, which overwrites console edits. - Never send the digest through your email provider directly. The journey’s send node routes it.
What you’ll build
This Node.js app turns each new comment into one Courier journey invoke:- A setup script that creates the journey, its per-user Batch node, and the digest template
- An Express endpoint that invokes the journey once per comment
Prerequisites
For the first send
- A Courier API key
- Node.js 22.18 or newer
For the full build
Clone the finished Node.js app
Clone the Courier Node.js digest quickstart to run the finished app with your own key:Install the Courier Node.js SDK and Express
The Courier Node.js SDK is@trycourier/courier on npm:
"type": "module" and add these scripts to package.json, which load .env with tsx --env-file. To type-check with tsc, copy the repo’s tsconfig.json, which allows .ts imports:
.env:
Create the digest notify function in Node.js
notifyNewComment invokes the Courier journey with client.journeys.invoke, which calls POST /journeys/{templateId}/invoke (templateId is the journey’s id), once per comment with an idempotency key.
lib/courier.ts
Define the digest journey with a Batch node
The Node.js setup script keeps the Courier journey in your repo, following Build with the API.scripts/setup.ts
npm run setup, copy the COURIER_DIGEST_JOURNEY_ID=... line it prints into .env, and restart npm run dev if it’s running. The Batch node reference covers every field.
Call the digest from your Express comment endpoint
The Express comment route saves the comment, then callsnotifyNewComment with the post’s author as the Courier recipient.
server.ts
Verify
SetDIGEST_WINDOW=PT1M in .env and rerun npm run setup so the Courier digest sends a minute after the first comment. Then:
- Run
npm run dev, then post three comments from a second terminal. Each prints a run id:In the cloned repo,npm run senddoes the same. - Open the journey’s Logs in Journeys. The first run waits at the Batch node.
- When the window closes, one email lists all three comments. Set
P1Dagain before production.
Go to production with Courier
Courier is notification infrastructure for humans and AI agents. It replaces the digest queue your Node.js app would otherwise run. Go live covers moving from Test to Production:- Run setup once per environment and store each journey ID.
- Link the template to a topic so Courier applies preferences.
- Log the run id to list its steps.
FAQ
How do I batch notifications in Node.js?
How do I batch notifications in Node.js?
Batching notifications in Node.js with Courier takes a journey with a Batch node and one
client.journeys.invoke call per event.How long can a digest batch wait?
How long can a digest batch wait?
A Courier Batch node waits at most 7 days, set by
max_wait_period. Its quiet window, wait_period, runs from 1 minute to 1 day.Can each user choose a daily or weekly digest?
Can each user choose a daily or weekly digest?
Per-user digest schedules come from a Courier subscription topic digest. A Batch node gives every user the same window.
Do I need BullMQ or a cron job to send a daily digest in Node.js?
Do I need BullMQ or a cron job to send a daily digest in Node.js?
A daily digest in Node.js needs no BullMQ, Redis, or cron job when a Courier Batch node holds the comments and sends the digest.