Skip to main content
Send each user one daily digest email from Node.js by invoking a Courier journey per comment. The journey’s Batch node holds the comments and sends one email when the window closes, instead of an email per comment.
Save it as first-send.mts, then run it with your API key and email address:
It prints a request id that you’ll find in Courier Logs. On a Test key, use your Courier login address. Test email reaches it with no provider connected.

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:
Install the Courier skill with 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/courier through the client in lib/courier.ts, not raw HTTP.
  • Read COURIER_API_KEY from the environment on the server. Never send it to a browser or commit .env.
  • Invoke the journey once per comment, with an Idempotency-Key built 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.ts and rerun npm 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

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:
The steps below add or change these files:

Install the Courier Node.js SDK and Express

The Courier Node.js SDK is @trycourier/courier on npm:
Set "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:
Put your key and address in .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
Run 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 calls notifyNewComment with the post’s author as the Courier recipient.
server.ts

Verify

Set DIGEST_WINDOW=PT1M in .env and rerun npm run setup so the Courier digest sends a minute after the first comment. Then:
  1. Run npm run dev, then post three comments from a second terminal. Each prints a run id:
    In the cloned repo, npm run send does the same.
  2. Open the journey’s Logs in Journeys. The first run waits at the Batch node.
  3. When the window closes, one email lists all three comments. Set P1D again 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

Batching notifications in Node.js with Courier takes a journey with a Batch node and one client.journeys.invoke call per event.
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.
Per-user digest schedules come from a Courier subscription topic digest. A Batch node gives every user the same window.
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.