Hono Security Monitoring With SecureNow: ESM Setup Guide
Add SecureNow security monitoring to a Hono app: the ESM preload flag, body capture, CLI setup, and PM2 or Docker production deployment.

Hono Security Monitoring With SecureNow: ESM Setup Guide
Hono is one of the fastest-growing web frameworks in the Node.js ecosystem — lightweight, multi-runtime, and built on Web Standard APIs. If you have picked Hono for your next API, adding security observability takes just one npm package and a single CLI flag.
There is one thing to know upfront: Hono uses ESM, so you need the -r preload flag instead of a require() call. This guide covers that caveat in detail, along with every other step from install to production deployment.
Prerequisites
- Node.js 22.23.4+, 24.22.1+, or 26.12.1+ installed
- An existing Hono project using
@hono/node-server(or willingness to scaffold one) - 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
Your project should already have hono and @hono/node-server installed. SecureNow does not require any Hono-specific adapter — it instruments the underlying Node.js http module that @hono/node-server uses internally.
Step 2: Log In via the CLI
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 the CLI 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)
The browser step of npx securenow login already took care of this: 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-hono-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 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-hono-api" },
"config": {
"logging": { "enabled": true },
"capture": { "body": true }
}
}
| Setting | Purpose |
|---|---|
app.key | Identifies your app in the dashboard. Written by login. |
apiKey | Runtime API key for telemetry ingestion and firewall sync. Secret: never commit it. |
config.logging.enabled | Forwards console.log/warn/error as OTel logs (default true). |
config.capture.body | Attaches request bodies to trace spans with sensitive fields redacted (default true). It works with @hono/node-server; if your setup reports request-stream conflicts, set it to false. URL parameters, headers, and trace metadata are captured either way. |
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, SECURENOW_CAPTURE_BODY and the other old SECURENOW_* variables are ignored.
Step 5: Instrument Your Hono App
Hono uses ES modules — your entry file is .mjs (or your package.json has "type": "module"). You cannot use require() inside ESM. Instead, preload SecureNow using the -r flag when starting Node.js.
Here is a complete Hono server in app.mjs:
import { serve } from '@hono/node-server';
import { Hono } from 'hono';
const app = new Hono();
app.get('/api/health', (c) => {
return c.json({ status: 'ok' });
});
app.get('/api/users', (c) => {
console.log('Fetching users', { query: c.req.query() });
return c.json([
{ id: 1, name: 'Alice' },
{ id: 2, name: 'Bob' },
]);
});
app.post('/api/users', async (c) => {
const body = await c.req.json();
console.info('Creating user', { email: body.email });
return c.json({ id: 3, ...body }, 201);
});
app.get('/api/users/:id', (c) => {
const id = c.req.param('id');
return c.json({ id: Number(id), name: 'Alice' });
});
app.onError((err, c) => {
console.error('Unhandled error', err);
return c.json({ error: 'Internal server error' }, 500);
});
const PORT = process.env.PORT || 3000;
serve({ fetch: app.fetch, port: Number(PORT) }, (info) => {
console.log(`Server running on port ${info.port}`);
});
Notice there is no SecureNow import in the file. The instrumentation is loaded externally via the -r flag.
The Critical Command
node -r securenow/register app.mjs
The -r flag tells Node.js to execute securenow/register (a CommonJS script) before the ESM loader processes app.mjs. This gives the OTel SDK time to monkey-patch the http module before Hono's node-server adapter creates the HTTP listener.
The same preload also forwards console.* calls as OTel logs, so no second -r flag is needed. Can't change the command itself? Use NODE_OPTIONS="-r securenow/register" node app.mjs, or the CLI wrapper npx securenow run app.mjs.
Adding to package.json
{
"type": "module",
"scripts": {
"start": "node app.mjs",
"start:observe": "node -r securenow/register app.mjs"
}
}
Step 6: Start and Verify
node -r securenow/register app.mjs
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 http://localhost:3000/api/users/1
curl -X POST http://localhost:3000/api/users -H "Content-Type: application/json" -d '{"name":"Charlie","email":"charlie@example.com"}'
Check your dashboard:
npx securenow status
You should see your app listed as protected. Browse traces:
npx securenow traces
Or open the full dashboard at app.securenow.ai.
Bonus: Useful CLI Commands
| Command | What It Does |
|---|---|
securenow traces | List recent traces |
securenow traces show <traceId> | Inspect a single trace |
securenow traces analyze <traceId> | AI-powered trace analysis |
securenow logs | List recent logs |
securenow notifications | View detected security issues |
securenow analytics | Traffic and performance analytics |
securenow ip <address> | Look up an IP address |
securenow blocklist add <ip> | Block a malicious IP |
securenow alerts rules | Manage alert rules |
securenow forensics | Run natural-language forensic queries |
Production Deployment with PM2
For production, use PM2 with an ecosystem config. The key difference for Hono is passing the preload via node_args and pointing script to the .mjs file:
// ecosystem.config.cjs
module.exports = {
apps: [{
name: 'my-hono-api',
script: './app.mjs',
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. The ecosystem file uses .cjs because PM2 config must be CommonJS even when your app is ESM.
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.mjs"]
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 URL paths
- 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
Body capture adds coverage for POST-body injection patterns; everything else works from URL, headers, and trace metadata. Issues surface in the dashboard and can trigger alerts via email, Slack, or custom webhooks.
Recap
| Step | Command / Action | Time |
|---|---|---|
| Install | npm install securenow | 10 s |
| Login | npx securenow login | 20 s |
| Create app | Pick or create it in the login browser step | 15 s |
| Configure | Nothing to edit: defaults live in .securenow/runtime.json | 0 s |
| Instrument | Use -r securenow/register flag | 10 s |
| Verify | npx securenow status | 10 s |
One flag, one package, zero code changes. Your Hono API is now observable and protected.
Next Steps
- Explore the SecureNow dashboard to view traces, logs, and security issues
- Set up alert rules for critical security events
- Run
npx securenow forensicsto ask natural-language questions about your traffic - Read the runtime config reference for advanced tuning
Happy shipping — and happy securing.
Frequently Asked Questions
Why can't I use require('securenow/register') in my Hono app?
Hono applications use ES modules (.mjs files or 'type': 'module' in package.json). ESM does not support require(). Instead, use the -r flag to preload the module: node -r securenow/register app.mjs. The -r flag runs CommonJS preload scripts before the ESM loader kicks in.
Does body capture work with Hono?
Yes, on @hono/node-server, and it is on by default. The SDK observes the Node.js request stream that @hono/node-server reads to build Hono's web-standard Request, without consuming it. If your setup reports request-stream conflicts, set config.capture.body to false in .securenow/runtime.json; request metadata, headers, and URL parameters are still fully captured.
Can I use SecureNow with Hono running on Bun or Deno?
SecureNow is built on the Node.js OpenTelemetry SDK. For Hono apps running on @hono/node-server under Node.js, it works fully. On Bun, bun --preload securenow/register only covers apps served through node:http; Bun.serve, which Hono on Bun normally uses, is not supported. Deno is not supported.
Does SecureNow detect attacks even without body capture?
Yes. Most attack detection — SQL injection in query strings, path traversal, anomalous traffic patterns, credential stuffing, and IP reputation — works from URL, headers, and trace metadata alone. Body capture adds coverage for POST-body injection patterns but is not required.
Recommended reading
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 27Built 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 26Part 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