Logo of AppSignal

Menu
Documentation navigation

Express

Express.js v4+ can be instrumented via a middleware plugin to augment Spans with richer data.

1
2
yarn add @appsignal/nodejs @appsignal/express
npm install --save @appsignal/nodejs @appsignal/express

You can then import and use the package in your app:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const { Appsignal } = require("@appsignal/nodejs")

const appsignal = new Appsignal({
  active: true,
  name: "<YOUR APPLICATION NAME>"
  apiKey: "<YOUR API KEY>"
})

const express = require("express")
const { expressMiddleware } = require("@appsignal/express")

const app = express()

// ADD THIS AFTER ANY OTHER EXPRESS MIDDLEWARE, BUT BEFORE ANY ROUTES!
app.use(expressMiddleware(appsignal))

The module also contains a middleware for catching any errors passed to next().

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const { Appsignal } = require("@appsignal/nodejs")

const appsignal = new Appsignal({
  active: true,
  name: "<YOUR APPLICATION NAME>"
  apiKey: "<YOUR API KEY>"
})

const express = require("express")
const { expressErrorHandler } = require("@appsignal/express")

const app = express()

// ADD THIS AFTER ANY OTHER EXPRESS MIDDLEWARE, AND AFTER ANY ROUTES!
app.use(expressErrorHandler(appsignal))

An example Express app, containing usage of all of our middleware and custom instrumentation can be found here.

We'd like to set cookies, read why.