Node.js SDK

0. Prerequisites

  1. A working Node.js application.

  2. Access to your HyperTest dashboard to get your API Key and Service ID.

circle-exclamation

1. Installing node-SDK package

npm install @hypertestco/node-sdk-v3 nyc --save-exact 

2. Initializing sdk

2.1 Create ht-init file

ht-init.js or ht-init.ts
// process.env.APPLY_HT_OTEL_PATCH = 'yes'; // Set this env only if opentelemetry is already being used in your application.

import * as htSdk from '@hypertestco/node-sdk-v3'; // for esm/ts
// const htSdk = require('@hypertestco/node-sdk-v3'); // for commonJS

// hypertest runs only if process.env.HT_MODE is set to 'RECORD'.
// It is safe to run this code as-is in production because HT_MODE wont be set to RECORD there
htSdk.initialize({
    apiKey: '<your-api-key>',
    serviceId: '<your-service-identifier-from-dashboard>',
    serviceName: '<organizationName:service-name>',
    exporterUrl: '<hypertest-logger-url>'
});

2.3 import ht-init file at the top in entrypoint

Entrypoint is the first js/ts file that gets executed. It might be index.ts, app.ts, src/main.ts etc. check your package.json

circle-exclamation

3. Add ht-start command in package.json

Identify if you're running a commonJS app or an ESM app. CommonJS is legacy and the default option in older nodejs versions For a CommonJS app.

For an ESM app, you'll need to add a build step

4. Verifying traffic is captured

you should see these logs at the start of your application

Start sending http requests on your app running with hypertest sdk.

You should start seeing requests under All requests section on the dashboard

Last updated