h3 and Nitro Security Monitoring With SecureNow

Add SecureNow security monitoring to an h3 or Nitro app: CLI setup, instrumentation, body capture, PM2 and Docker deployment, and notes for Nuxt 3.

Mar 26, 2026·9 min read
getting started securenow h3 nitro

h3 and Nitro Security Monitoring With SecureNow

h3 is the minimal, high-performance HTTP framework from the UnJS ecosystem. It powers Nitro — and by extension Nuxt 3's entire server engine — which means a huge number of production APIs run on h3 without developers even realizing it. If you are building directly on h3 (or Nitro), you get blazing-fast event handlers. What you don't get is built-in security observability.

SecureNow changes that. A single require() line auto-instruments your h3 application with OpenTelemetry-powered tracing, so SQL injection probes, credential stuffing, API abuse, and anomalous traffic are surfaced in real time — without adding middleware or rewriting handlers.

This guide walks you through the full integration: install, CLI authentication, app creation, runtime config, instrumentation, and production deployment with PM2 and Docker.

...

Prerequisites

  • Node.js 22.23.4+, 24.22.1+, or 26.12.1+ installed
  • An existing h3 project (or willingness to scaffold a quick one)
  • A terminal and a browser

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

...

Step 1: Install the Package

Open your project directory and install securenow:

npm install securenow

This single package bundles the OpenTelemetry SDK, auto-instrumentations for Node.js, an OTLP exporter, the SecureNow CLI, and optional console-log forwarding. There is nothing else to install.

...

Step 2: Log In via the CLI

SecureNow ships a CLI as securenow (or npx securenow if you installed it locally). 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

You should see your email and account details printed in the terminal.

...

Step 3: Create an Application (Free Trial)

Every application you monitor in SecureNow gets a unique identifier (the 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-h3-api
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 like securenow traces and securenow status 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-h3-api" },
  "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). h3's readBody works alongside the capture hook, so body capture is fully supported. 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 h3 App

You have two options — pick whichever fits your workflow.

Option A: One Line at the Top of Your Entry File (Recommended)

Add this line before any other require:

require('securenow/register');

const http = require('http');
const { createApp, createRouter, defineEventHandler, readBody, toNodeListener } = require('h3');

const app = createApp();
const router = createRouter();

router.get('/health', defineEventHandler(() => {
  return { status: 'ok', timestamp: new Date().toISOString() };
}));

router.post('/tasks', defineEventHandler(async (event) => {
  const body = await readBody(event);
  console.log('Creating task', { title: body.title, priority: body.priority });
  const task = {
    id: Date.now(),
    title: body.title,
    priority: body.priority || 'medium',
    createdAt: new Date().toISOString(),
  };
  event.node.res.statusCode = 201;
  return task;
}));

app.use(router);

const PORT = process.env.PORT || 3000;
http.createServer(toNodeListener(app)).listen(PORT, () => {
  console.log(`h3 server running on http://localhost:${PORT}`);
});

securenow/register starts the OpenTelemetry SDK, reads .securenow/runtime.json, and auto-instruments HTTP, database drivers, and more. It also forwards console.* calls as OTel log records so they appear alongside your traces in the dashboard; no second preload is needed. This works in CommonJS files; ESM ("type": "module") and TypeScript (tsx) apps use the preload flag in Option B.

Option B: Zero Code Changes with the Preload Flag

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

node -r securenow/register app.js

Can't change the command itself? Set the flag through NODE_OPTIONS, or use the CLI wrapper:

NODE_OPTIONS="-r securenow/register" node app.js
npx securenow run app.js

Or add it to your package.json scripts:

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

Then run:

npm run start:observe
...

Step 6: Start and Verify

Run your app:

node app.js

You should see confirmation in your terminal:

[securenow] OTel SDK started → https://ingest.securenow.ai/v1/traces
[securenow] 📋 Logging: ENABLED → https://ingest.securenow.ai/v1/logs
h3 server running on http://localhost:3000

Generate some traffic — curl http://localhost:3000/health a few times — then check your dashboard:

npx securenow status

You should see your app listed as protected. You can also browse traces directly from the terminal:

npx securenow traces

Or open the full dashboard at app.securenow.ai to explore traces, logs, security issues, and analytics.

...

Bonus: Useful CLI Commands

Once your app is instrumented, the CLI becomes your terminal-based control plane:

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-h3-api',
    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.

...

A Note on Nitro and Nuxt 3

h3 is the HTTP layer inside Nitro, and Nitro is the server engine inside Nuxt 3. If you are building a standalone h3 or Nitro server (outside of Nuxt), the integration above works as-is. If you are running a full Nuxt 3 or 4 application, add securenow/nuxt to modules in nuxt.config and run npx securenow init (settings still come from .securenow/runtime.json, not from a securenow: { ... } options block). Or build without the module and instrument the Nitro build output (the .output/server/index.mjs file) rather than a hand-written app.js: start it with node -r securenow/register .output/server/index.mjs (under PM2: script: '.output/server/index.mjs' with node_args: ['-r', require.resolve('securenow/register')] in ecosystem.config.cjs), and everything else stays the same.

...

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.json (body capture on)0 s
Instrumentnode -r securenow/register app.js or one require() line30 s
Verifynpx securenow status10 s

Six steps, five minutes, zero handler changes. Your h3 API is now observable and protected.

...

Next Steps

Happy shipping — and happy securing.

Frequently Asked Questions

Does SecureNow work with Nitro and Nuxt 3 server routes?

Yes. h3 is the HTTP framework that powers Nitro, which is Nuxt 3's server engine. SecureNow's auto-instrumentation hooks into the underlying Node.js HTTP layer, so it captures every h3/Nitro handler — including Nuxt server routes, API routes, and middleware — without any Nuxt-specific configuration.

Can I enable request body capture with h3?

Yes, and it is on by default (config.capture.body in .securenow/runtime.json). The SDK observes the request stream without consuming it, so h3's readBody function works alongside SecureNow's body capture, and request payloads are attached to trace spans with sensitive fields automatically redacted.

Do I need to install any h3-specific plugin for SecureNow?

No. SecureNow auto-instruments via Node.js preload and hooks into the standard HTTP layer that h3 builds on. No plugins, no defineNitroPlugin, and no changes to your event handlers are needed.

Does SecureNow work with PM2 cluster mode and h3?

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. h3 runs on a plain Node.js HTTP server, so clustering behaves identically to any other Node.js app.

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