Docs/Integrations/Node.js / NestJS

Node.js / NestJS Integration

Native support for Node.js, NestJS, Express, and Fastify.

The NxtOne Node.js SDK runs inside your Node.js process and sends behavioral events straight to the NxtOne platform over HTTPS — there is no separate process, container, or daemon to run. A single package, @nxtone/agent, covers both TypeScript and JavaScript.

1. Install the package

The SDK requires Node.js 20.6+.

bash
npm install @nxtone/agent

NestJS apps also install the NestJS adapter:

bash
npm install @nxtone/nest

2. Loading the SDK

The SDK has to load before your application code. The simplest way is Node's --import flag, which needs no code changes and loads the SDK before any of your modules:

bash
node --import @nxtone/agent/register dist/main.js

Alternatively, initialize it in code: call nxtone.init() and wait for it before your server starts listening, then start Node normally.

JavaScript / Express (index.js)
javascript
import * as nxtone from '@nxtone/agent'; import express from 'express'; async function start() { await nxtone.init({ projectId: 'api-service' }); const app = express(); app.get('/api', (req, res) => { res.json({ ok: true }); }); app.listen(3000); } start();

3. NestJS

Register NxtOneModule.forRoot() from @nxtone/nest in your root module:

TypeScript / NestJS (app.module.ts)
typescript
import { Module } from '@nestjs/common'; import { NxtOneModule } from '@nxtone/nest'; @Module({ imports: [NxtOneModule.forRoot()], }) export class AppModule {}

Keep loading the SDK itself with --import. For a standard Nest project, update the production start script in package.json:

json
"scripts": { "start:prod": "node --import @nxtone/agent/register dist/main" }

If you call nxtone.init() instead, await it at the top of bootstrap() in main.ts, before app.listen().

4. Configuration

Configure the SDK with environment variables. Keep the API key out of your code — set it in the environment or your platform's secret store:

bash
export NXTONE_API_KEY="<your-api-key>" export NXTONE_PROJECT_ID="gateway-service"
VariableDefaultDescription
NXTONE_API_KEYrequiredWithout it the SDK does nothing (it prints a hint to stderr) and never fails your app.
NXTONE_PROJECT_IDunknownGroups execution flows in the UI. Set it explicitly per service, here or with nxtone.init({ projectId }).
NXTONE_EXCLUDE—Packages or paths to leave uninstrumented.

The Node.js SDK also reads NXTONE_VALUE_ENCRYPTION and NXTONE_TELEMETRY, and a config file at ./nxtone.properties or ~/.nxtone/config.properties. It reads no other environment variables, so settings documented for the Java or Python SDKs — such as NXTONE_LOG_LEVEL or a shutdown timeout — have no effect here.

5. Shutdown

The SDK batches events in memory and flushes them when the process exits, for up to 5 seconds (not configurable). It does not spool to disk, so events still in memory when the process is killed are lost.

Start your app with node, not npx nxtone run. The npx nxtone run launcher does not forward SIGTERM to your app, so in a container your app can be killed without shutting down cleanly — and lose its last events.

6. Verifying the connection

On startup the SDK prints NXTONE_SESSION_ID=<uuid> to stderr. If you see a hint that the API key is missing instead, the SDK is running as a no-op — check the environment the process actually received. Then send a request and check that its execution flow appears in NxtOne under your project ID.

The SDK only makes outbound HTTPS (443) connections — to www.api.nxtone.ai and to Amazon S3 for large values — and opens no ports. If nothing shows up, work through Troubleshooting.