DEV Community

DarshanBattula
DarshanBattula

Posted on

strict-env-validator

I kept breaking apps because of missing env variables… so I built this.

Hey everyone 👋

I’ve lost count of how many times this happened:

  • App crashes in production
  • Turns out → missing or invalid .env variable
  • Or worse… typo like DATABSE_URL 😅

So I built a small utility to fix this problem:

👉 strict-env-validator

🔗 https://www.npmjs.com/package/strict-env-validator


🔧 What it does

  • Automatically loads .env files
  • Validates all environment variables at startup
  • Throws clear errors if something is missing or invalid
  • Prevents your app from running with bad config

✨ Why I built it

I tried existing tools, but I wanted something:

  • Simpler to use
  • Strict by default
  • Works out of the box without too much setup

Most tools validate env variables, but I wanted something that fails fast and clearly before your app even starts.


⚡ Example

Instead of writing validation manually:

const PORT = process.env.PORT;
if (!PORT) throw new Error("Missing PORT");
Enter fullscreen mode Exit fullscreen mode

You get:

import "strict-env-validator";
Enter fullscreen mode Exit fullscreen mode

And it handles everything for you ✅


🎯 Goal

Make .env handling:

  • predictable
  • safe
  • impossible to mess up

🙌 Feedback

This is still early, so I’d really appreciate:

  • feedback
  • feature ideas
  • criticism

If you’ve faced similar issues, I’d love to hear how you handle env validation.

Thanks!

Top comments (0)