Connect Express to Bugsink

When an Express request fails, Bugsink shows you the exception, the application frame that raised it, and the HTTP request that reached the route.

This guide covers the initial setup and Express’s automatic capture of errors that reach its error-handling chain. You’ll connect an existing application, then make one request fail to confirm that it reaches Bugsink.

To follow along, create a Bugsink project and copy its DSN. The quickstart guide shows where to find it.

Install the SDK

Install the open-source Sentry SDK alongside Express. Bugsink accepts the Sentry event protocol, so the SDK can send events directly to your project:

npm install @sentry/node

Initialize the SDK before Express

Create an instrumentation module which initializes the SDK from the DSN in the environment:

import * as Sentry from "@sentry/node";


Sentry.init({
  dsn: process.env.SENTRY_DSN,
});

Import that module before importing Express or the rest of your application. The order matters because the SDK instruments modules as they load:

import "./instrument.mjs";

import * as Sentry from "@sentry/node";
import express from "express";

Set SENTRY_DSN in the environment where the server runs:

export SENTRY_DSN=https://key@bugsink.example/1

Add the Express error handler

Define your routes first, then add the SDK’s error handler before your own final Express error handler:

Sentry.setupExpressErrorHandler(app);

app.use((error, request, response, next) => {
  response.status(500).json({ error: error.message, eventId: response.sentry });
});

The SDK observes the exception and passes it on. Your own handler still decides which response the client receives.

Trigger an unhandled route exception

There is no reporting call inside a route. To verify the setup, this checkout route throws when the requested product is missing:

app.get("/checkout/:sku", (request, response) => {
  const product = inventory.get(request.params.sku);
  if (!product) {
    throw new ProductNotFound(`Product ${request.params.sku} is not in inventory`);
  }
  response.json({ reserved: product.name });
});

Start the application as usual, then request a missing product:

npm start
:::bash
curl http://127.0.0.1:3000/checkout/express-missing

Express returns an HTTP 500 response and the SDK reports the exception.

See the error in Bugsink

Open your Bugsink project and select the new ProductNotFound issue. Its event points to the failing line in the route and includes the GET request.

Bugsink preview

That’s it: errors reaching Express’s error handler will now be reported to Bugsink. Your routes remain ordinary application code, while Bugsink receives their JavaScript stack and request context.

For handled exceptions, messages, tags, structured context, and breadcrumbs, continue with the Node.js guide.