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.
Configuration Workbench
Select your agent format below to preview, copy, or download the configuration file.
# 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`.
Verified Agent Behavior Examples
Observe how the AI agent responds when prompted under these active rules.
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.