Star us on GitHub
Star
Welcome to highlight.io
Company
Mission & Values
Compliance & Security
Open Source
Getting Started
Overview
Fullstack Mapping
Backend / Server
Frontend / Client
Fullstack Frameworks
Product Features
Session Replay
Error Monitoring
General Features
Logging
Integrations
Integrations Overview
Amplitude Integration
ClickUp Integration
Discord Integration
Electron Support
Front Integration
Height Integration
Intercom Integration
Linear Integration
Mixpanel Integration
Segment Integration
Slack Integration
Vercel Integration
Tips
Content-Security-Policy
Local Development
Monkey Patches
Performance Impact
Proxying Highlight
Session Search Deep Linking
Troubleshooting
Upgrading Highlight
Highlight.io Changelog
Changelog 12 (02/17)
Menu
Docs / Highlight Docs / Getting Started / Backend / Server / Express Backend

Express Backend

Highlight ships @highlight-run/node which can be installed alongside highlight.run for capturing backend errors in applications with Express backends.

Usage

The usage of this Backend SDK requires one of our Client SDKs to be installed, so please follow the instructions there if you have not done so.

The @highlight-run/node Package

First, import the package

yarn add @highlight-run/node
Copy
Adding Highlight to Express

Pass configurations into the errorHandler and Highlight is ready to go!

Where you place the app.use(highlightErrorHandler) definition is important. It must be set after route handler definitions (app.get(...), etc) and before other error middleware.

import * as Highlight from '@highlight-run/node' // or like this with commonjs // const Highlight = require('@highlight-run/node') const app = express() // define any configurations needed // <https://docs.highlight.run/api/hinit#w0-highlightoptions> const highlightOptions = {} // initialize the handler const highlightErrorHandler = Highlight.Handlers.errorHandler(highlightOptions) app.get('/', (req, res) => { if (Math.random() < 0.1) { throw new Error(`random error ${Math.random()}`) } res.send(`Hello World! ${Math.random()}`) }) // This should be before any other error middleware and after all controllers (route definitions) app.use(highlightErrorHandler) app.listen(port, () => { console.log(`Example app listening on port ${port}`) })
Copy
Verify

To validate your Highlight backend setup, you'll need to setup up a testing route handler that throws an error. See the block above for an example. Add some code to your frontend to make an HTTP request to /error. You should be able to view your frontend session making the request and find the error traceback in the errors page.

To view and resolve the recorded error, log into app.highlight.io and open your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved.