Node.js SDK with CJS
How to add nodejs sdk into your application
1. Installing node-SDK package
npm install @hypertestco/node-sdk --save-exact 2. Initializing sdk
2.1 Adding SDK in code and Initialize
Initalize hypertest node sdk.
This needs to happen as early in your app as possible. Make sure no require/import call is made before these lines
// process.env.APPLY_HT_OTEL_PATCH = 'yes'; // Set this env only if opentelemetry is already being used in your application.
process.env.HT_MODE = process.env.HT_MODE || 'RECORD'; // TODO: REMOVE THIS LINE BEFORE DEPLOYING TO PRODUCTION
import * as htSdk from '@hypertestco/node-sdk'; // for esm/ts
// const htSdk = require('@hypertestco/node-sdk'); // for commonJS
htSdk.initialize({
apiKey: '<your-api-key>',
serviceId: '<your-service-identifier-from-dashboard>',
serviceName: '<organizationName:service-name>',
exporterUrl: '<hypertest-logger-url>',
// ignoredHostsForHttpReqs: ['abc.xyz.com', /^\d+\.abcd\.co(m|)$/],
// disableInstrumentations: [] // htSdk.HtInstrumentations enum
});
// No imports or require calls should be made before htSdk.initialize is called. Fight your instincts and your linters for this :)2.2 Mark app as ready
Call the markAppAsReady method when the app is ready to receive traffic, it indicates that tests can be started (This is important ONLY FOR REPLAY mode).
2.3 Enable Test Creation
To enable hypertest, set the HT_MODE env variable to RECORD and start your app
OR while booting
2.4 Set env if opentelemetry is already being used.
3. Verifying traffic is captured
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