errorcoredocsbeta
Framework guides

NestJS

npm install errorcore

Initialize Errorcore before creating the Nest app when possible.

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 = await NestFactory.create(AppModule);
app.use(expressMiddleware());

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

This uses Nest's default Express adapter. expressMiddleware() attaches request context; call captureError(exception) from the application's existing global exception filter for handled production failures. Avoid wrapping every controller manually.

On this page