env-reloader
v1.1.1
Published
Auto-restart Node.js server on .env changes | dotenv reload watcher for development
Maintainers
Readme
env-reloader
🚀 env-reloader is a lightweight CLI tool that automatically restarts your Node.js server whenever the .env file changes.
Perfect for development environments where you frequently update environment variables.
✨ Features
- 📂 Watches
.envfile for changes - ⚡ Automatically restarts your Node.js / TypeScript server
- 🎯 Lightweight & easy to use
- 🖥 Works on Windows, macOS, and Linux
📦 Installation
Install globally:
npm install -g env-reloaderOr install locally (for project-specific use):
npm install --save-dev env-reloader🛠 Usage (JavaScript)
1️⃣ Create a .env file
PORT=3000
MESSAGE=Hello from env-reloader!2️⃣ Create a test server (server.js)
require('dotenv').config();
console.log("Server running with PORT:", process.env.PORT);
console.log("Message:", process.env.MESSAGE);3️⃣ Add script in package.json (if installed locally)
"scripts": {
"dev": "env-reloader server.js"
}4️⃣ Run the server
If installed globally:
env-reloader server.jsIf installed locally (via npm script):
npm run dev🛠 Usage (TypeScript)
1️⃣ Install ts-node and typescript in your project:
npm install --save-dev ts-node typescript2️⃣ Create a test server (server.ts):
import dotenv from "dotenv";
dotenv.config();
console.log("Server running with PORT:", process.env.PORT);
console.log("Message:", process.env.MESSAGE);3️⃣ Run with env-reloader:
env-reloader src/server.ts👉 It will automatically use ts-node if available.
🔄 How it Works
Starts your server (
.jswith Node OR.tswith ts-node)Watches the
.envfile for changesOn
.envchange:- Stops the server
- Reloads
.env - Restarts the server
📌 Example Workflow
Run your project with
env-reloader server.js(orserver.ts)Change something in
.env:PORT=4000 MESSAGE=Updated message!The server automatically restarts and loads the new values without manual intervention.
