DEV Community

CinfiniteDev
CinfiniteDev

Posted on

From Chaos to Control: Multiple Node.js Environments with Multi-Env CLI

⚡ Multi-Env CLI

Stop juggling .env files for Node.js projects. Run multiple environments side-by-side with hot-reload support.


💡 Why Multi-Env CLI?

If you’ve ever worked on a Node.js project, you know the pain of juggling multiple environments.

For testing a feature across dev, staging, and prod, every time we needed to tweak an environment variable, we typically:

  • 🛑 Stop the server
  • 📄 Copy .env to .env.staging or .env.prod
  • 🔄 Restart the app
  • 👀 Double-check which instance was running

By the end of the day, we had three terminals open, three versions of .env floating around — it felt like manually juggling spinning plates.


💡 The Thought

There has to be a better way.

That’s how Multi-Env CLI came to life — a small CLI tool that:

  • 🚀 Runs multiple Node.js instances at the same time
  • ✏️ Lets you edit environment variables live without restarting
  • 🔒 Keeps your original .env files untouched
  • 🛠️ Makes it easy to list, kill, and manage instances

🔥 Pain Points Solved

Before Multi-Env CLI, developers often ran into:

  • 📂 Constantly copying .env files for each environment
  • 🔄 Restarting the server every time a variable changes
  • 🤯 Losing track of which instance is running which environment

With Multi-Env CLI, all of that is gone:

  • 📝 Temporary env files for each instance
  • ⚡ Hot reload — editing the temp env automatically restarts the app
  • 📋 Instance management — list, kill, and clean up instances safely

🛠️ Typical Workflow

  • Generic Multi-Env CLI Command
npx multi-env run --env-file <path-to-env-file> --cmd "<your-command>"
Enter fullscreen mode Exit fullscreen mode
  • Run a staging instance
npx multi-env run --env-file .env.staging --cmd "node server.js" --auto-cleanup
Enter fullscreen mode Exit fullscreen mode
  • Edit Environment Variables Live

Open .multi-env/env.temp.

Change variables and save → the app restarts automatically

  • Run Production Instance Simultaneously
npx multi-env run --env-file .env.prod --cmd "node server.js"
Enter fullscreen mode Exit fullscreen mode
  • List Running Instances
npx multi-env list
Enter fullscreen mode Exit fullscreen mode
  • Kill Any Instance When Done
npx multi-env kill --id <instance-id>
Enter fullscreen mode Exit fullscreen mode

✨ Key Features

  • 📝 Hot-editable env files — no more manual restarts

  • 🔀 Run multiple instances side by side (dev, staging, prod)

  • 📂 CLI-managed temp files — original .env stays safe

  • 🛡️ Crash-safe — dead instances are cleaned automatically

  • Plug-and-play — works with any Node.js project

👥 Who It’s For

  • 💻 Node.js developers running multiple environments locally

  • 🧪 Teams testing feature flags or environment-dependent features

  • 🚀 Anyone doing rapid prototyping, CI/CD testing, or multi-tenant apps

🚀 Getting Started

Install globally:

npm install -g multi-env-cli
Enter fullscreen mode Exit fullscreen mode

Or use via npx without installing:

npx multi-env run
Enter fullscreen mode Exit fullscreen mode

📂 Temp Env Files

All temp env files are stored in .multi-env/ inside your project

Original .env files are never modified

Editing temp env files triggers auto-restart for the specific instance


🏁 Ending Note

Multi-Env CLI was built to make working with multiple Node.js environments simpler, faster, and safer. No more juggling .env files, restarting servers manually, or losing track of instances.

Whether you’re testing feature flags, running dev/staging/prod side by side, or experimenting with rapid prototyping, this tool helps you stay in control — and keeps your workflow smooth and stress-free.

Give it a try, and see how much easier managing Node.js environments can be! 🚀

“Temp files are my playground — shuffle, duplicate, or vanish them without breaking a sweat.” — The Env Whisperer

npm link: https://www.npmjs.com/package/multi-env-cli

Top comments (0)