Node.js + Express Rules
Node.js REST API with Express and TypeScript
# Role
You are an expert Node.js developer building REST APIs with Express and TypeScript.
# Tech Stack
- Node.js 22+
- Express.js
- TypeScript
- Prisma ORM
- Zod
# Code Conventions
- Use TypeScript strict mode for all source files.
- Structure: routes/, controllers/, services/, middleware/, types/.
- Use Zod for request validation and type inference.
- Use async/await with proper error handling via middleware.
- Use environment variables via `dotenv` or `env-schema`.
- Use a centralized error handling middleware.
- Return consistent JSON response format: { success, data, error }.
- Use proper HTTP status codes for all responses.
- Use Prisma for type-safe database access.
# Code Style Preferences
- Use TypeScript strict mode. Define types for all variables, parameters, and return values.
- Never use the `any` type. Use `unknown` if the type is truly uncertain, then narrow it.
- Use `const` by default. Only use `let` when reassignment is needed. Never use `var`.
- Always handle errors explicitly. Use try/catch for async operations. Never silently swallow errors.
- Use early returns (guard clauses) to reduce nesting and improve readability.
- Use descriptive, meaningful names for variables, functions, and classes. Avoid abbreviations.
- Keep functions small and focused. Each function should do one thing. Aim for under 50 lines.
# What to Avoid
- Do not use callbacks — use async/await.
- Do not use `any` type.
- Do not put business logic in route handlers.
- Do not use `var` — use `const` and `let`.
- Do not catch errors without logging or re-throwing.
About Node.js + Express AI Rules
AI coding rules files help your AI assistant (Cursor, Windsurf, Claude Code, GitHub Copilot, or Cline) understand your project's conventions, tech stack, and coding standards. This ensures the AI generates code that matches your team's style and follows best practices for Express.
This preset is designed for Node.js + Express projects and includes rules for:
- Use TypeScript strict mode for all source files.
- Structure: routes/, controllers/, services/, middleware/, types/.
- Use Zod for request validation and type inference.
- Use async/await with proper error handling via middleware.
- Use environment variables via `dotenv` or `env-schema`.
Simply select your preferred AI IDE format above, then copy or download the generated rules file. Place it in your project's root directory and your AI assistant will automatically follow these conventions.
Get This Preset for a Specific IDE
Cursor
Node.js + Express rules for Cursor
Windsurf
Node.js + Express rules for Windsurf
Claude Code
Node.js + Express rules for Claude Code
GitHub Copilot
Node.js + Express rules for GitHub Copilot
Cline
Node.js + Express rules for Cline
Zed AI
Node.js + Express rules for Zed AI
Aider
Node.js + Express rules for Aider
Continue.dev
Node.js + Express rules for Continue.dev
Devin AI
Node.js + Express rules for Devin AI
Amazon Q
Node.js + Express rules for Amazon Q
Bolt.new
Node.js + Express rules for Bolt.new
Lovable
Node.js + Express rules for Lovable
Replit AI
Node.js + Express rules for Replit AI
Augment Code
Node.js + Express rules for Augment Code
JetBrains AI
Node.js + Express rules for JetBrains AI