Raw Node.js HTTP Server Security Monitoring With SecureNow

Add security monitoring to a raw Node.js http.createServer app with SecureNow. No framework or middleware: one npm package, CLI setup, PM2 and Docker.

Mar 26, 2026·8 min read
getting started securenow micro http

Raw Node.js HTTP Server Security Monitoring With SecureNow

Not every Node.js service needs Express, Fastify, or Koa. Sometimes http.createServer and a handful of helper functions are all you need. If that describes your stack, SecureNow fits right in — it instruments the core http module at the runtime level, so there is no middleware to add, no framework plugin to configure, and no code to rewrite.

This guide covers the full path from an empty terminal to a fully monitored raw HTTP server: installing the package, authenticating, creating an app on the free trial, checking the runtime config, writing a minimal server, and verifying that traces land in the dashboard.

...

Prerequisites

  • Node.js 22.23.4+, 24.22.1+, or 26.12.1+ installed
  • A project directory (even an empty one — we will create a server from scratch)
  • A terminal and a browser

No SecureNow account yet? The CLI will open a browser-based signup/login flow for you.

...

Step 1: Install the Package

npm install securenow

That is the only dependency you need. There is no separate framework adapter, no OpenTelemetry boilerplate, and no config file generator. securenow bundles the full OTel SDK, auto-instrumentations, the OTLP exporter, and the CLI.

...

Step 2: Log In via the CLI

Authenticate with one command:

npx securenow login

A browser tab opens at app.securenow.ai where you can sign up or log in, then pick an application or create a new one. The CLI writes two gitignored files in your project: .securenow/runtime.json (the app key and runtime API key the SDK runs with) and .securenow/admin.json (the authorization every subsequent CLI command uses).

Prefer a non-interactive flow? Generate a CLI token from your dashboard at Settings → CLI Token, then run:

npx securenow login --token YOUR_TOKEN

A token login only authorizes the CLI. Link the project to an app afterwards with npx securenow apps default <app-key> and npx securenow api-key create, which write .securenow/runtime.json.

Verify you are logged in:

npx securenow whoami
...

Step 3: Create an Application (Free Trial)

Every monitored service gets a unique app key. The browser step of npx securenow login already took care of it: the app you picked or created there is linked to this project, and its app key and runtime API key are saved in .securenow/runtime.json. There is nothing to copy into a .env file.

To create an app from the terminal instead:

npx securenow apps create my-http-server
npx securenow apps default a1b2c3d4-e5f6-7890-abcd-ef1234567890
npx securenow api-key create

apps default links the app to this project (it writes .securenow/runtime.json) and makes CLI commands target it automatically. api-key create saves the runtime API key that telemetry ingestion and firewall sync authenticate with.

...

Step 4: Check the Runtime Config

There is no .env file to write. The SDK reads its settings from .securenow/runtime.json, and every setting has a secure default, so the file works as login wrote it. The parts that matter here look like this:

{
  "apiKey": "snk_live_...",
  "app": { "key": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "name": "my-http-server" },
  "config": {
    "logging": { "enabled": true },
    "capture": { "body": true }
  }
}
SettingPurpose
app.keyIdentifies your app in the dashboard. Written by login.
apiKeyRuntime API key for telemetry ingestion and firewall sync. Secret: never commit it.
config.logging.enabledForwards console.log/warn/error as OTel logs (default true).
config.capture.bodyAttaches request bodies to trace spans (default true). Works perfectly with raw HTTP — sensitive fields are automatically redacted.

The SDK reads only two environment variables: SECURENOW_CREDENTIALS, for hosts that cannot mount a file, and SECURENOW_DISABLED=1, which turns it off (for example in tests). SECURENOW_APPID, SECURENOW_INSTANCE and the other old SECURENOW_* variables are ignored.

...

Step 5: Instrument Your Raw HTTP Server

Add require('securenow/register') as the very first line of your entry file — before any other require. This is the most important detail: the OTel SDK must load before the http module so it can monkey-patch createServer.

require('securenow/register');

const http = require('http');

function readBody(req) {
  return new Promise((resolve, reject) => {
    const chunks = [];
    req.on('data', (chunk) => chunks.push(chunk));
    req.on('end', () => resolve(Buffer.concat(chunks).toString()));
    req.on('error', reject);
  });
}

function sendJson(res, statusCode, data) {
  res.writeHead(statusCode, { 'Content-Type': 'application/json' });
  res.end(JSON.stringify(data));
}

const server = http.createServer(async (req, res) => {
  const url = new URL(req.url, `http://${req.headers.host}`);

  if (req.method === 'GET' && url.pathname === '/api/health') {
    return sendJson(res, 200, { status: 'ok' });
  }

  if (req.method === 'GET' && url.pathname === '/api/users') {
    console.log('Fetching users', { query: Object.fromEntries(url.searchParams) });
    return sendJson(res, 200, [
      { id: 1, name: 'Alice' },
      { id: 2, name: 'Bob' },
    ]);
  }

  if (req.method === 'POST' && url.pathname === '/api/users') {
    const body = JSON.parse(await readBody(req));
    console.info('Creating user', { email: body.email });
    return sendJson(res, 201, { id: 3, ...body });
  }

  sendJson(res, 404, { error: 'Not found' });
});

const PORT = process.env.PORT || 3000;
server.listen(PORT, () => {
  console.log(`Server running on port ${PORT}`);
});

No middleware, no plugins, no decorators. This is the most minimal setup possible — pure Node.js with zero framework overhead. The same require also forwards console.* calls as OTel logs; no second preload is needed. It works in CommonJS files; ESM ("type": "module") and TypeScript (tsx) apps use the preload flag below.

Alternative: Zero Code Changes with the Preload Flag

If you prefer not to touch your source files, pass the preload flag to Node:

node -r securenow/register app.js

Can't change the command itself? Use NODE_OPTIONS="-r securenow/register" node app.js, or the CLI wrapper npx securenow run app.js.

Or add it to package.json:

{
  "scripts": {
    "start": "node app.js",
    "start:observe": "node -r securenow/register app.js"
  }
}
...

Step 6: Start and Verify

Run your app:

node app.js

You should see:

[securenow] OTel SDK started → https://ingest.securenow.ai/v1/traces
[securenow] 📋 Logging: ENABLED → https://ingest.securenow.ai/v1/logs
Server running on port 3000

Generate some traffic:

curl http://localhost:3000/api/health
curl http://localhost:3000/api/users
curl -X POST http://localhost:3000/api/users -H "Content-Type: application/json" -d '{"name":"Charlie","email":"charlie@example.com"}'

Check your dashboard from the terminal:

npx securenow status

You should see your app listed as protected. Browse traces directly:

npx securenow traces

Or open the full dashboard at app.securenow.ai.

...

Bonus: Useful CLI Commands

CommandWhat It Does
securenow tracesList recent traces
securenow traces show <traceId>Inspect a single trace
securenow traces analyze <traceId>AI-powered trace analysis
securenow logsList recent logs
securenow notificationsView detected security issues
securenow analyticsTraffic and performance analytics
securenow ip <address>Look up an IP address
securenow blocklist add <ip>Block a malicious IP
securenow alerts rulesManage alert rules
securenow forensicsRun natural-language forensic queries
...

Production Deployment with PM2

For production, use PM2 with an ecosystem config:

// ecosystem.config.cjs
module.exports = {
  apps: [{
    name: 'my-http-server',
    script: './app.js',
    instances: 4,
    exec_mode: 'cluster',
    node_args: ['-r', require.resolve('securenow/register')],
    env: {
      NODE_ENV: 'production',
    }
  }]
};
pm2 start ecosystem.config.cjs

require.resolve makes the preload an absolute path: in cluster mode a bare -r securenow/register is resolved from the PM2 daemon's folder, so the workers crash when the daemon was started elsewhere (for example by pm2 resurrect at boot). No SecureNow environment variables are needed: in fork and cluster mode, each worker reads the .securenow/ folder of the app PM2 started, and all workers report under the same service name. On the server, that folder needs the production credentials: npx securenow credentials runtime --env production writes them to .securenow/credentials.production.json; copy that file to the server as .securenow/credentials.json.

...

Docker Deployment

FROM node:22.23.4-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
# Mount the production credentials at /app/.securenow/credentials.json
# (generated by: npx securenow credentials runtime --env production)
ENV NODE_ENV=production
EXPOSE 3000
CMD ["node", "-r", "securenow/register", "app.js"]

On hosts that cannot mount a file (Railway, Render, Heroku, Fly.io), set a SECURENOW_CREDENTIALS secret to the value printed by npx securenow credentials runtime --env production --format env instead.

...

What SecureNow Detects Automatically

Once traces are flowing, SecureNow watches for:

  • SQL injection — malicious patterns in query parameters and request bodies
  • XSS attempts — script injection in user input
  • Credential stuffing — high-velocity failed authentication attempts
  • API abuse — unusual request patterns, rate-limit evasion, unauthorized endpoint access
  • Anomalous traffic — AI-powered detection of behavioral outliers
  • Supply-chain signals — unexpected outbound calls from your service
  • Performance degradation — slow queries, high error rates, latency spikes

All of this happens without writing a single detection rule. Security issues surface in the dashboard and can trigger alerts via email, Slack, or custom webhooks.

...

Recap

StepCommand / ActionTime
Installnpm install securenow10 s
Loginnpx securenow login20 s
Create appPick or create it in the login browser step15 s
ConfigureNothing to edit: defaults live in .securenow/runtime.json0 s
InstrumentAdd require('securenow/register') as first line30 s
Verifynpx securenow status10 s

No framework, no middleware, no overhead. Your raw HTTP server is now observable and protected.

...

Next Steps

Happy shipping — and happy securing.

Frequently Asked Questions

Does SecureNow work without any web framework?

Yes. SecureNow instruments the core Node.js http module directly. Any server built with http.createServer — including micro-frameworks, custom routers, or plain handler functions — is automatically traced.

Can I capture request bodies with raw HTTP?

Yes, and it is on by default (config.capture.body in .securenow/runtime.json). SecureNow observes the request stream to capture body content without consuming it. Sensitive fields like passwords and tokens are automatically redacted before export.

What is the performance overhead of SecureNow on a raw HTTP server?

Minimal. The OpenTelemetry SDK adds single-digit millisecond overhead per request. For most APIs, the difference is undetectable in production. You can disable body capture or logging to reduce it further.

Does SecureNow work with PM2 cluster mode on a raw HTTP server?

Yes. Use node_args: ['-r', require.resolve('securenow/register')] in ecosystem.config.cjs: in cluster mode a bare -r is resolved from the PM2 daemon's folder, so the workers crash when the daemon was started elsewhere (for example by pm2 resurrect at boot). No environment variables are needed: every worker reads the app's .securenow/ folder and reports under the same service name.

Recommended reading

Block an IP, a Range or One Route Without a Deploy (Node.js)

Block one IP, a CIDR range, or a single route and method in a Node.js app within seconds, with no code change: setup, scoping, CLI, MCP, verification and undo.

Oct 27
11 Signs Your AI-Built App Needs a Security Audit

Built your app with a coding agent? 11 warning signs it needs a security audit, each checkable in five minutes, and how to run the full audit yourself.

Oct 26
AI Security Audit Part 1: Set Up Your Agent to Audit Code

Part 1 of the AI security audit series: set up an AI coding agent to audit your app locally, connect SecureNow, and run your first threat-model pass.

Jul 24