Star us on GitHub
Star
Menu

Node.js

Learn how to set up highlight.io in Node.js.
1
Add `tracingOrigins` to your client Highlight snippet.

This backend SDK requires one of the Highlight frontend SDKs to be installed, so please make sure you've followed the fullstack mapping guide first.

H.init("<YOUR_PROJECT_ID>", { tracingOrigins: ['localhost', 'example.myapp.com/backend'], networkRecording: { enabled: true, recordHeadersAndBody: true, }, });
Copy
2
Install the Highlight JS SDK.

Install the @highlight-run/node package with your package manager.

# with yarn yarn add @highlight-run/node # with pnpm pnpm add @highlight-run/node # with npm npm install @highlight-run/node
Copy
3
Initialize the Highlight JS SDK.

Initialize the Highlight JS SDK with your project ID.

import { H } from '@highlight-run/node' H.init({projectID: 'YOUR_PROJECT_ID'})
Copy
4
Optionally, report manual errors in your app.

If you need to report exceptions outside of a handler, use the Highlight SDK.

const parsed = H.parseHeaders(request.headers) H.consumeError(error, parsed?.secureSessionId, parsed?.requestId)
Copy
5
Verify that your SDK is reporting errors.

You'll want to throw an exception in one of your Node.js handlers. Access the API handler and make sure the error shows up in Highlight.

const onError = (request, error) => { const parsed = H.parseHeaders(request.headers) H.consumeError(error, parsed.secureSessionId, parsed.requestId) } const main = () => { try { throw new Error('example error!') } catch (e) { onError(e) } }
Copy
6
Verify your backend logs are being recorded.

With the JS SDKs, your logs are reported automatically from console methods. Visit the highlight logs portal and check that backend logs are coming in.