🟢

GitHub Copilot Rules for Node.js + Express

Node.js REST API with Express and TypeScript

Node.jsExpressTypeScriptREST
.github/copilot-instructions.md
# GitHub Copilot Instructions

## Context
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

## Conventions to Follow
- 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
- 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.

## Do Not
- 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 GitHub Copilot Rules for Node.js + Express

The .github/copilot-instructions.md file helps GitHub Copilot understand your Node.js + Express 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 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`.

How to use this file

  1. Click Copy or Download above.
  2. Place the .github/copilot-instructions.md file in your project's root directory.
  3. GitHub Copilot will automatically detect and apply these rules.

Get Node.js + Express Rules for Other IDEs

Other GitHub Copilot Presets