Backend Boilerplates javascript Beginner

Node.js Startup Env Validator

Fail fast on process start if required environment variables are absent or empty.

javascript
const required = ['DATABASE_URL', 'JWT_SECRET', 'PORT'];
for (const key of required) {
  if (!process.env[key]) {
    console.error('[FATAL] Missing env var:', key);
    process.exit(1);
  }
}
module.exports = {
  db:   process.env.DATABASE_URL,
  jwt:  process.env.JWT_SECRET,
  port: Number(process.env.PORT),
};

Prerequisites

  • Node.js >= 16

Pro Tips

  • → Import as the very first line of your entry point.

Was this module useful?

Share your experience — it helps the team improve.

Leave Feedback

Commercial Licensing

Acquire a production access token or template license for enterprise deployment.

Module Info

Language
javascript
Level
Beginner
Read time
1 min
Published
Jun 2024
License
Commercial License

Newsletter

New modules every week, directly to your inbox.