Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Run Node services with a restart policy (process management)
Use OS/container orchestration restart policies; avoid ad-hoc scripts that hide failures.
Bad example
| 1 | // package.json |
| 2 | { |
| 3 | "scripts": { |
| 4 | "start": "node server.js", |
| 5 | "prod": "while true; do node server.js; done" |
| 6 | } |
| 7 | } |
Explanation (EN)
A naive loop can mask crashes, remove backoff, and make it harder to observe and manage failures properly.
Objašnjenje (HR)
Naivna petlja može sakriti crash, ukloniti backoff i otežati praćenje i upravljanje kvarovima.
Good example
| 1 | // ecosystem.config.js (pm2 example) |
| 2 | module.exports = { |
| 3 | apps: [ |
| 4 | { |
| 5 | name: "api", |
| 6 | script: "./dist/server.js", |
| 7 | instances: 1, |
| 8 | autorestart: true, |
| 9 | max_restarts: 10, |
| 10 | min_uptime: 5000, |
| 11 | env: { |
| 12 | NODE_ENV: "production", |
| 13 | PORT: "3000" |
| 14 | } |
| 15 | } |
| 16 | ] |
| 17 | }; |
Explanation (EN)
A defined restart policy makes failures visible and recovery consistent. Prefer OS/container policies when available; a process manager is an acceptable alternative.
Objašnjenje (HR)
Definiran restart policy čini kvarove vidljivima i oporavak konzistentnim. Preferiraj OS/container policy gdje je moguće; process manager je prihvatljiva alternativa.