If you've built a Node.js application, you've probably used dotenv.
The typical setup looks like this:
1️⃣ Install dotenv
2️⃣ Create a .env file
3️⃣ Access values with process.env
import "dotenv/config"
const db = process.env.DATABASE_URL
For years, this workflow has worked fine.
But once applications grow, things start to break down.
The Hidden Problems with dotenv
As projects scale, teams often run into issues like:
• missing environment variables
• runtime crashes from bad configuration
• manually sharing .env files between developers
• no validation or type safety
dotenv solves loading environment variables.
But it doesn't solve managing them.
The Typical dotenv Workflow
A typical .env file might look like this:
DATABASE_URL=postgres://localhost:5432/app
JWT_SECRET=mysecret
PORT=3000
Then inside your application:
import "dotenv/config"
const port = process.env.PORT
This works — but it also means:
- everything is a string
- nothing is validated
- errors happen at runtime
What I Wanted Instead
I started thinking about what a modern environment workflow should look like.
Ideally it should have:
• validation
• type safety
• a CLI workflow
• a better way to share variables across teams
So I built PushEnv.
dotenv vs PushEnv
| Feature | dotenv | PushEnv |
|---|---|---|
| Simple env loading | ✓ | ✓ |
| Validation | ✗ | ✓ |
| Type safety | ✗ | ✓ |
| CLI workflow | ✗ | ✓ |
| Team sync | ✗ | ✓ |
dotenv is still great for small projects.
But modern applications often need stronger configuration management.
A Better Approach
With PushEnv, environment variables are defined using a schema.
Example:
import { z } from "zod"
export const envSchema = {
DATABASE_URL: z.string().url(),
PORT: z.number(),
JWT_SECRET: z.string()
}
Now invalid configurations are caught before the application even starts.
CLI Workflow
PushEnv also introduces a CLI workflow for managing environment variables.
pushenv init
pushenv push
pushenv pull
This makes it easier to synchronize environment variables across teams.
When Should You Use Each?
Use dotenv if:
• you're building a quick prototype
• you're working on a small personal project
PushEnv works best for:
• production applications
• teams collaborating on projects
• applications that require configuration validation
Try PushEnv
PushEnv is open source and available on GitHub.
You can try it in seconds:
npm install pushenv
pushenv init
pushenv push
GitHub: https://github.com/shahnoormujawar/pushenv
If you're interested in improving environment variable management, I'd love to hear your feedback.
Top comments (0)