Env and secrets
Describe your environment once. railguard checks it at startup, turns strings into real numbers and booleans, and keeps your secrets out of git.
- A missing
MONGO_DBor aPORTof"five-thousand"stops the app at boot, not on the first request. - A typo like
env.MONGO_URLthrows instead of quietly returningundefined. console.log(env)prints[secret]for passwords and tokens.- Database URLs with passwords, Gmail app passwords, AWS, GitHub, Stripe, OpenAI and Anthropic keys, JWTs and private keys are blocked at commit.
- A
.envthat isn't git-ignored, or is still tracked after you ignored it, is flagged.
// env.schema.js (npx railguard init writes it from your .env.example) const { t } = require('railguard') module.exports = { PORT: t.port().default(5000), MONGO_DB: t.url(), JWT_SECRET: t.string({ min: 32 }).secret(), SENDER_EMAIL: t.email(), NODE_ENV: t.enum(['development', 'production']), } // server.js const env = guard(require('./env.schema')) app.listen(env.PORT) // a number, not "5000"