Skip to main content
Node.js & Enterprise REST APIsbackendTarget: Node.js 20+ LTS / Express / Hono

Node.js & Backend REST API AI Agent Rules & Cursorrules

Turn AI coding assistants into enterprise Node.js systems engineers.

Prevent memory leaks and unhandled promise crashes. Enforce enterprise Node.js standards including structured JSON logging, graceful SIGTERM shutdowns, and rate limiting.

#nodejs cursorrules#node js cursor rules#nodejs claude md#backend agent rules nodejs#cursor rules for express

Configuration Workbench

Select your agent format below to preview, copy, or download the configuration file.

Cursor configuration for Node.js enterprise backends.
10 lines•0.5 KB
# Node.js Backend Cursor Rules

You are a Principal Systems Engineer specializing in Node.js.

## Core Rules
- Runtime: Node.js 20+ LTS with ESM modules ('import/export').
- Asynchronous: Never use synchronous blocking APIs ('readFileSync', 'crypto.pbkdf2Sync').
- Structured Logging: Use Pino with trace IDs. NEVER use 'console.log' in production code.
- Graceful Shutdown: Handle process 'SIGTERM' and 'SIGINT' to drain active HTTP connections and close database pools.
- Error Handling: Centralized error handling middleware. Catch unhandled rejections.

Pro-tip: Place this file directly in the root directory of your Node.js & Enterprise REST APIs project. AI agents like Cursor Composer, Claude Code, and GitHub Copilot will read it automatically on initialization.

Architectural Principles Enforced

When this configuration file is loaded into Cursor or Claude Code, the agent strictly enforces the following design invariants:

Always listen for `SIGTERM` and `SIGINT` signals to perform graceful database and connection shutdowns.

Use structured JSON logging (Pino) with correlation IDs rather than unstructured `console.log`.

Never block the event loop with synchronous file operations (`readFileSync`) or heavy CPU algorithms.

Return standardized error payloads (RFC 7807 Problem Details) with HTTP status codes.

Enforce helmet security headers, CORS policies, and token bucket rate limiters.

Installation & Repository Setup

Place in project root as `.cursorrules` or `CLAUDE.md`.

1Copy `.cursorrules` to your Node.js service root.
2Ensure Pino or Winston is configured for structured logging.

Verified Agent Behavior Examples

Observe how the AI agent responds when prompted under these active rules.

Scenario: Implementing graceful shutdown
User prompt: “Write a server bootstrap script that gracefully drains connections on SIGTERM.”
Agent Behavior: The agent implements a clean listener on `process.on('SIGTERM')` that stops accepting new connections, drains the database pool, and exits with code 0.

Frequently Asked Questions

Why should I ban console.log in Node.js rules?

`console.log` is synchronous and can block the Node.js event loop during high-throughput spikes. Structured loggers like Pino buffer output asynchronously and output machine-readable JSON.