Express TypeScript Development
You are an expert in Express.js and TypeScript development with deep knowledge of building scalable, maintainable APIs.
TypeScript General Guidelines
Basic Principles
- Use English for all code and documentation
- Always declare types for variables and functions (parameters and return values)
- Avoid using
anytype - create necessary types instead - Use JSDoc to document public classes and methods
- Write concise, maintainable, and technically accurate code
- Use functional and declarative programming patterns; avoid classes where possible
- Prefer iteration and modularization to adhere to DRY principles
Nomenclature
- Use PascalCase for types and interfaces
- Use camelCase for variables, functions, and methods
- Use kebab-case for file and directory names
- Use UPPERCASE for environment variables
- Use descriptive variable names with auxiliary verbs:
isLoading,hasError,canDelete - Start each function with a verb
Functions
- Write short functions with a single purpose
- Use arrow functions for middleware and handlers
- Use async/await consistently throughout the codebase
- Use the RO-RO pattern for multiple parameters
Types and Interfaces
- Prefer interfaces over types for object shapes
- Avoid enums; use maps or const objects instead
- Use Zod for runtime validation with inferred types
- Use
readonlyfor immutable properties
Express-Specific Guidelines
Project Structure
Application Setup
Middleware Patterns
- Use middleware for cross-cutting concerns
- Chain middleware in order of execution
- Handle errors in dedicated error middleware
Routing
- Organize routes by resource
- Use Router for modular route definitions
- Apply middleware at appropriate levels
Request Validation
- Validate all incoming requests
- Use Zod for schema definition and validation
- Create reusable validation middleware
Error Handling
- Create custom error classes
- Use centralized error handler middleware
- Return consistent error responses
TypeScript Extensions
Extend Express types for custom properties:
Security Best Practices
- Use helmet for security headers
- Implement rate limiting
- Sanitize user inputs
- Use HTTPS in production
- Implement CORS properly
Testing
- Use Jest with supertest for integration tests
- Test middleware in isolation
- Mock external dependencies


