errorcoredocsbeta
Framework guides

Express

npm install errorcore
import express from "express";
import { captureError, expressMiddleware, flush, init } from "errorcore";

init({
  service: process.env.ERRORCORE_SERVICE_NAME,
  deploymentEnv: process.env.ERRORCORE_ENVIRONMENT,
  transport: {
    type: "http",
    url: process.env.ERRORCORE_INGEST_URL ?? "https://api-production-7ecf.up.railway.app/v1/ingest",
    apiKey: process.env.ERRORCORE_API_KEY,
  },
  encryptionKey: process.env.ERRORCORE_DEK,
});

const app = express();
app.use(expressMiddleware());

app.get("/errorcore-test", async (_request, response) => {
  captureError(new Error("errorcore test error"));
  await flush();
  response.status(202).json({ sent: true });
});

expressMiddleware() attaches request context; it does not replace your error handler. Call captureError(error) from the application's existing final Express error middleware so handled route failures are captured. Keep ERRORCORE_API_KEY and ERRORCORE_DEK in server env only.

On this page