pn-node-backend

A set of rules for writing Node.js backend and API code, with TypeScript or documented JavaScript types where needed.

In plain words
What is it for?
Use it when building or reviewing routes, services, environment configuration, input handling, and centralized error handling.
Why use it?
It helps prevent common server problems involving asynchronous code, missing configuration, exposed secrets, swallowed errors, and inconsistent responses.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/perniemann/pncore/pn-node-backend
Clone the repo
git clone --depth 1 https://github.com/perniemann/pnCore
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 711 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00711
Opus 5 $0.00000 $0.00356
Sonnet 5 $0.00000 $0.00142
Haiku 4.5 $0.00000 $0.00071

Measured yesterday against content hash 752ff9db112f, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

pn-node-backend scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

packages/pn-core-mcp/content/rules/pn-node-backend.mdc · 44 lines

How it starts

The opening of the file, as written. The whole thing — 44 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Node / backend rules

Variables and style

  • Prefer const over let; use let only when reassignment is needed. Never use var.
  • Use async/await over raw promise chains. Never mix callbacks with promises in the same flow.
  • TypeScript types or JSDoc at all public API boundaries; avoid any. Use unknown + type narrowing for external input.
  • Small functions, single responsibility. Handlers delegate to services — route files stay thin.

Secrets and config

  • All config and secrets come from environment variables (process.env.VAR). Never hardcode keys, passwords, or connection strings in source.
  • Validate required env vars at startup, not lazily at use-time: if (!process.env.DB_URL) throw new Error("DB_URL is required").
  • Keep a .env.example with placeholder names; document every required variable in README. Never commit .env to git.

Error handling

  • Catch errors at boundaries (route handlers, service entry points); propagate with throw internally. Never swallow errors silently.
  • Use a centralized Express error middleware — route handlers throw or call next(err); the middleware formats and sends the response.
  • Return consistent error shapes: { error: { code: string, message: string, requestId: string } }.
  • Map errors to correct HTTP status codes: 400 bad input, 401 unauthenticated, 403 forbidden, 404 not found, 422 validation failed, 429 rate limited, 500 unexpected.
  • Use structured logging (pino, winston). Include requestId, userId, and relevant IDs in every log line. Never log secrets or PII.

Security

  • Parameterized queries always — never interpolate user input into SQL or commands.
  • Validate and parse all request input before use. Use zod or similar at route boundaries.
  • Scope data queries to the authenticated user's ID. Never trust a client-supplied userId.
  • Apply helmet for security headers. Configure CORS with an explicit origin allowlist, not *.
  • Rate-limit auth routes (/login, /register) more aggressively than general API routes.

Read the full file on GitHub · 44 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 44 lines · 0 tokens per session scan A 752ff9db112f

Subscribe to this mod's changes

pn-node-backend is a cursor rule published in the GitHub repository perniemann/pnCore (0 stars, last pushed 2d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 711 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.