CommonJS (CJS)

Learn about running Sentry in an CJS application.

Most node applications today are either written in CommonJS (CJS), or compiled to CJS before running them. CommonJS uses require() to load modules. Our recommended installation method when using CommonJS is to require the instrument.js file at the top of your application.

Copied
// Require this first!
require('./instrument');

// Now require other modules
const express = require('express');
const Sentry = require('@sentry/node');

const app = express();

// Add your routes, etc.

// Add this after all routes and other middlewares are defined
Sentry.setupExpressErrorHandler(app);

app.listen(3000);
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").