Skip to content
English

Blog · 31 October 2026

Error monitoring for Node.js and Express

From Express route to forgotten await: everything in one overview.

A Node.js process that crashes is restarted by your process manager, and nobody notices. Until it happens every hour. A promise without catch even disappears completely. With the Sentry SDK for Node and errors.nl you see those errors, with the request and the stack trace.

1. Create a project

Create a free account at errors.nl (or log in), create an organization and a project and copy the DSN. It looks like https://<key>@ingest.errors.nl/<project>.

2. Install the SDK

npm install @sentry/node

3. Load it first

The SDK must be loaded before you import other modules. Put the setup in its own file, instrument.js:

const Sentry = require("@sentry/node");

Sentry.init({
  dsn: process.env.SENTRY_DSN,
  environment: process.env.NODE_ENV,
  release: process.env.SENTRY_RELEASE,
});

And load that file as the very first line of your app:

require("./instrument");
const express = require("express");

Using ES modules? Start your app with node --import ./instrument.mjs app.mjs.

4. Hook up your framework

For Express, add the error handler after all your routes, and before your own error handlers:

const app = express();
// ... your routes
Sentry.setupExpressErrorHandler(app);

For Fastify use Sentry.setupFastifyErrorHandler(app), for Koa Sentry.setupKoaErrorHandler(app).

5. Test it

app.get("/error-test", () => {
  throw new Error("Test error for errors.nl");
});

Call the route, and within seconds the error shows up under Issues. The SDK catches unhandled promises and exceptions outside a request by itself.

6. Workers and scripts

In a queue worker or cron script you catch errors yourself and send them on. In a short script, wait until everything has been sent before the process exits:

try {
  await processInvoices();
} catch (e) {
  Sentry.captureException(e);
  await Sentry.flush(2000);
  process.exit(1);
}

Personal data

Leave sendDefaultPii off: the SDK then sends no IP addresses, cookies or request body. errors.nl does no performance monitoring; if you don't set tracesSampleRate, the SDK doesn't send that data either.

On top of that, errors.nl filters passwords, tokens, e-mail addresses and account numbers from every error before we store it. Read more in Error monitoring and the GDPR.

Notifications

Want to know when something goes wrong without keeping the dashboard open? Turn on e-mail notifications for your project, or connect Slack, Teams, Discord or ntfy for push notifications on your phone.

Start for free View the demo