|
| 1 | +--- |
| 2 | +# Node.js Backend Project Guidelines |
| 3 | +--- |
| 4 | + |
| 5 | +### Project Setup |
| 6 | +- Use **Node.js (v18+)** and **Express.js** for building APIs. |
| 7 | +- Store configuration in environment variables (`.env`), and use the config files already present, if they exist. |
| 8 | +- follow ES6+ JavaScript conventions. |
| 9 | + |
| 10 | +### Style & Formatting |
| 11 | +- Use **camelCase** for variables and function names. |
| 12 | +- Apply **2-space indentation**. |
| 13 | +- Prefer **single quotes** for strings. |
| 14 | +- Always use **async/await** for asynchronous operations. |
| 15 | +- Use **ESLint** with the **Airbnb Base** style guide (see `.eslintrc` or `package.json`). |
| 16 | + |
| 17 | + |
| 18 | +### Architecture & Patterns |
| 19 | +- Organize code into clear layers: `routes/`, `controllers/`, `services/`, `models/`. |
| 20 | +- Keep business logic in services; route handlers should be thin. |
| 21 | + |
| 22 | +### Error Handling & Security |
| 23 | +- Implement centralized error handling middleware (must include status codes and JSON error messages), or adhere to existing code that handles it |
| 24 | +- Always validate and sanitize inputs. |
| 25 | +- For cookies or sessions, ensure `httpOnly`, `secure` (in prod), and `sameSite: 'strict'`. |
| 26 | + |
| 27 | +### Testing |
| 28 | +- Use **Mocha** for unit tests, always look for /tests/*/*.js or /test/*.js to learn the styling and test formats |
| 29 | +- Maintain ≥80% test coverage. |
| 30 | + |
| 31 | +### Build & Deployment |
| 32 | +- Build command: `npm run build`. |
| 33 | +- Start server with `npm start`; |
| 34 | + |
| 35 | +### Documentation & Maintenance |
| 36 | +- Tag PRs with [FEATURE], [BUGFIX], or [REFACTOR]. |
| 37 | + |
| 38 | +--- |
| 39 | + |
| 40 | +```markdown |
| 41 | +--- |
| 42 | +applyTo: "tests/**/*.js" |
| 43 | +--- |
| 44 | + |
| 45 | +# Test File Guidelines |
| 46 | +- Write clear, descriptive test names. |
| 47 | +- Use `describe` and `it` blocks from Jest. |
| 48 | +- Clean up any test data or mocks after each test. |
0 commit comments