- Node.js >= 18.0.0
- MongoDB >= 5.0
- Git
- npm or yarn
- VS Code or Zed (recommended)
- ESLint
- Prettier
- MongoDB for VS Code
- REST Client
- GitLens
-
Variables
- Use
constfor values that won't be reassigned - Use
letfor values that will be reassigned - Never use
var - Use meaningful variable names
- Use
-
Functions
- Use arrow functions for callbacks
- Use regular functions for methods
- Use async/await for asynchronous operations
-
Objects
- Use object destructuring
- Use object shorthand notation
- Use computed property names when appropriate
-
Arrays
- Use array destructuring
- Use array methods (map, filter, reduce)
- Use spread operator for array operations
-
Files
- Use kebab-case for file names
- Use
.jsextension for JavaScript files - Use
.test.jsfor test files
-
Variables and Functions
- Use camelCase for variables and functions
- Use PascalCase for classes and components
- Use UPPER_CASE for constants
-
Database
- Use snake_case for database fields
- Use plural form for collection names
- Use singular form for model names
- Test individual functions and components
- Mock external dependencies
- Use Jest for testing framework
- Aim for high test coverage
- Test API endpoints
- Test database operations
- Test authentication flows
- Test error handling
# Run all tests
npm test
# Run tests with coverage
npm run test:coverage
# Run specific test file
npm test -- path/to/test.js
# Run tests in watch mode
npm test -- --watch- Use Mongoose schemas
- Define indexes for frequently queried fields
- Use appropriate data types
- Add validation rules
- Use migrations for schema changes
- Version control migration files
- Test migrations before applying
- Create seed data for development
- Include test cases
- Document seed data structure
- Use RESTful conventions
- Version APIs
- Use appropriate HTTP methods
- Include proper status codes
- Validate all inputs
- Use Joi for validation
- Return clear error messages
- Handle edge cases
{
"success": true,
"data": {},
"meta": {
"page": 1,
"limit": 10,
"total": 100
}
}- ValidationError
- AuthenticationError
- AuthorizationError
- NotFoundError
- DatabaseError
{
"success": false,
"error": {
"code": "ERROR_CODE",
"message": "Error message",
"details": {}
}
}- ERROR: For errors that need immediate attention
- WARN: For potentially harmful situations
- INFO: For general operational information
- DEBUG: For detailed debugging information
{
"timestamp": "2024-01-01T00:00:00.000Z",
"level": "info",
"message": "Operation completed",
"context": {
"userId": "123",
"operation": "create_report"
}
}- Use appropriate indexes
- Implement pagination
- Use lean queries when possible
- Cache frequently accessed data
- Implement rate limiting
- Use compression
- Enable caching headers
- Optimize response payload
- Use JWT for authentication
- Implement refresh tokens
- Secure password storage
- Rate limit login attempts
- Use role-based access control
- Validate permissions
- Sanitize user inputs
- Prevent SQL injection
- Use .env for local development
- Use environment variables in production
- Never commit sensitive data
- Document all required variables
- Use production build
- Minify assets
- Optimize images
- Enable compression
- Set up error tracking
- Monitor performance
- Track user activity
- Set up alerts