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).
Export services via port binding
The app should be self-contained and listen on a configurable port (PORT), not rely on external web servers.
Bad example
| 1 | // ❌ Assumes a fixed port and hidden infrastructure assumptions |
| 2 | import express from "express"; |
| 3 |
|
| 4 | const app = express(); |
| 5 | app.get("/health", (_req, res) => res.send("ok")); |
| 6 |
|
| 7 | app.listen(3000); |
Explanation (EN)
Hardcoding ports breaks container and platform deployments where the runtime assigns the port. It also makes parallel local dev harder.
Objašnjenje (HR)
Hardkodiranje porta ruši container/platform deploy gdje runtime dodjeljuje port. Također otežava paralelni lokalni dev.
Good example
| 1 | // ✅ Bind to PORT provided by the environment |
| 2 | import express from "express"; |
| 3 |
|
| 4 | const app = express(); |
| 5 | app.get("/health", (_req, res) => res.send("ok")); |
| 6 |
|
| 7 | const port = Number(process.env.PORT ?? "3000"); |
| 8 | app.listen(port, () => console.log(`listening on :${port}`)); |
Explanation (EN)
Binding to an environment-provided port makes the service portable across local, staging, and container/PaaS environments.
Objašnjenje (HR)
Bindanje na port iz okruženja čini servis prenosivim kroz lokalno, staging i container/PaaS okruženja.
Notes (EN)
From the 12-Factor point on exporting services via port binding.
Bilješke (HR)
Iz 12-Factor točke o izvozu servisa kroz port binding.