Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
backend ruleP2universalStack: Node.js
performanceconfigconstants
Read env vars and constants once, not inside hot functions
Resolve `process.env` values and other invariant constants once at module load / class construction, not on every function call. Env values never change during a process lifetime, so re-reading and re-deriving them per invocation is wasted work and scatters magic strings.
PR: profico-org-corpus batch2 (all stacks/products)Created: Jul 26, 2026
Bad example
Old codets
| 1 | function sign(payload) { |
| 2 | const secret = process.env.TOKEN || 'fallback'; |
| 3 | const algorithm = 'HS256'; |
| 4 | return jwt.sign(payload, secret, { algorithm }); |
| 5 | } |
Explanation (EN)
The secret and algorithm are re-resolved on every call even though they never change.
Objašnjenje (HR)
Good example
New codets
| 1 | const SECRET = process.env.TOKEN || 'fallback'; |
| 2 | const ALGORITHM = 'HS256'; |
| 3 |
|
| 4 | function sign(payload) { |
| 5 | return jwt.sign(payload, SECRET, { algorithm: ALGORITHM }); |
| 6 | } |
Explanation (EN)
Constants are computed once at load and referenced by name.
Objašnjenje (HR)