Node.js
Express.js

Express.js Web Application

On this page, we help you install ShortLoop SDK in your Express.js web application, so that it can automatically sample traffic.

Install

Add ShortLoop Node.js SDK from public npm registry.

npm install @shortloop/node@0.0.12

Configure

To configure the SDK, you need to add it as a middleware in your application.

Import the SDK from installed package.

import { ShortloopSDK } from '@shortloop/node';

Initialize SDK with options - url and applicationName as shown in below example and register the middleware.

const app = express();
app.use(express.json());
app.use(express.text()); //...any other middlewares for body parsing
ShortloopSDK.init({
  url: "https://shortloop.company-name.com", // ShortLoop URL. (Provided by ShortLoop team.)
  applicationName: "service-name", // your application name here
  authKey: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // ShortLoop Auth Key. (Provided by ShortLoop team.)
  environment: "your-environment" // for e.g stage or prod
});
app.use(ShortloopSDK.capture());

To mask sensitive headers, provide a list as maskHeaders field as shown in below example.

Note that maskHeaders field is optional and headers are case insensitive.

...
ShortloopSDK.init({
  url: "https://shortloop.company-name.com", // ShortLoop URL. (Provided by ShortLoop team.)
  applicationName: "service-name", // your application name here
  authKey: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // ShortLoop Auth Key. (Provided by ShortLoop team.)
  environment: "your-environment" // for e.g stage or prod
  maskHeaders: ["cookie", "x-auth"] // [Optional]. The following headers values will be masked at the SDK level itself. (Will not be sent to the server)
});
...

Verify

Quickly test if project is building after configuring SDK.

⚠️

Build command maybe custom to your project.

npm run build

After the changes, redeploy your Express.js application.

Feel free to email for a quick support, reporting bug or improvements suggestions. Sumit B Mulchandani (sumit@shortloop.dev)

Copyright © 2023 ShortLoop, Inc. All rights reserved.