DEV Community

Rahul Chourasiya
Rahul Chourasiya

Posted on

Why I Stopped Using .env Files (And What I Use Instead)

Like most developers, our team relied on .env files for years. It felt simple: create a .env.local, put your API keys in it, and add it to .gitignore.

In practice, that system always breaks:

  1. The Slack DM leak: When a new engineer joins, someone pastes the staging database URL into a private Slack thread.
  2. The Git commit accident: A developer renames a file or initializes a new subfolder, forgets to add .env to .gitignore, and pushes production keys to GitHub.
  3. Environment drift: Staging has variables that dev doesn't, causing the classic "it worked on my machine" outage.

The In-Memory Approach

Instead of storing secrets in plaintext files on disk, we can fetch encrypted credentials over TLS and inject them directly into the child process memory at runtime.

I built a CLI called Ray Secrets (@rcmade/ray) to make this zero-friction:

# 1. Install & Authenticate
npm install -g @rcmade/ray
ray login

# 2. Link your project (auto-imports existing .env if present)
ray init

# 3. Launch your app with in-memory injection
ray run -e development -- npm run dev
Enter fullscreen mode Exit fullscreen mode

Why this changes local workflow:

  1. Zero Disk Exposure: The child process receives process.env in RAM. Nothing is written to .env. When the server stops, the secrets disappear from memory.
  2. Local AST Healing: If you still need a local file for legacy tools, ray sync reconciles differences and automatically repairs broken syntax without stripping comments.
  3. Production Proposals: Changes to production secrets can require review before landing, just like a GitHub Pull Request.

If you're tired of passing around .env files, give it a spin:

How is your team currently handling local and staging secrets?

Top comments (0)