Environment variables without the hassle - No installation, no imports, no configuration required.
A lightweight, dynamic environment variable loader for Node.js applications that works with any existing project without code modifications.
π Documentation Website | π¦ NPM Package | π Report Issues
The Problem with Other Solutions:
// β Other tools require code modification
require('dotenv').config(); // dotenv
require('dotenv-flow').config(); // dotenv-flow
const env = require('env-var'); // env-var
// β Or require project installation
npm install dotenv-cli // dotenv-cli
dotenv -e .env.dev -- node app.jsThe envx Solution:
# β
Works with ANY existing Node.js project
# β
NO code modification needed
# β
NO project dependencies required
npx @href00/envx your-app.js --env=dev- πͺ Zero Setup: Works with any existing Node.js project instantly
- π§ No Code Changes: Your application code stays exactly the same
- π Environment Overlays: Base
.env+ environment-specific files (.env.dev,.env.staging) - π Nodemon Integration: Built-in auto-reload with
envx-nodemon - π‘οΈ Production Safe: Configurable loading in CI/production environments
- π¦ Zero Dependencies: Lightweight with built-in dotenv parser
- ποΈ Legacy Friendly: Perfect for projects that can't be modified
# Install once, use everywhere
npm install -g @href00/envx
# Then use directly without npx
envx your-app.js --env=dev
envx-nodemon your-app.js --env=dev# Install in your project
npm install --save-dev @href00/envx
# Add to package.json scripts
{
"scripts": {
"dev": "envx-nodemon server.js --env=dev",
"start": "envx server.js --env=prod"
}
}
# Run via npm
npm run dev# Use directly (will prompt for installation)
npx @href00/envx your-app.js --env=dev
# Skip confirmation with --yes
npx --yes @href00/envx your-app.js --env=dev
npx --yes --package=@href00/envx envx-nodemon your-app.js --env=dev# Works with ANY existing Node.js project
npx @href00/envx your-app.js # Load .env
npx @href00/envx your-app.js --env=dev # Load .env + .env.dev
npx @href00/envx your-app.js --env=prod # Load .env + .env.prod
# With nodemon integration
npx --package=@href00/envx envx-nodemon server.js --env=dev # Auto-reload development# Got an old project that can't be modified? No problem!
npx @href00/envx legacy-app.js --env=production
# No need to add require() statements
# No need to install dependencies
# Just works!npx @href00/envx <entry.js> [options] -- [app-arguments]
Options:
--env=<name> Load environment-specific overlay (.env.<name>)
--allow-ci Allow loading env files in CI environment
--allow-prod Allow loading env files in production
--quiet Suppress envx output messages
Examples:
npx @href00/envx app.js --env=dev
npx @href00/envx app.js --env=staging --quiet
npx @href00/envx app.js --env=prod --allow-prod -- --port=3000
npx --package=@href00/envx envx-nodemon server.js --env=dev --watch src.env # Base environment (always loaded first)
.env.dev # Development overlay
.env.staging # Staging overlay
.env.production # Production overlay
.env (base):
DATABASE_URL=postgresql://localhost:5432/myapp
API_KEY=base-api-key
NODE_ENV=development.env.dev (development overlay):
DATABASE_URL=postgresql://dev-server:5432/myapp_dev
API_KEY=dev-api-key-override
REDIS_URL=redis://dev-redis:6379.env.staging (staging overlay):
DATABASE_URL=postgresql://staging-server:5432/myapp_staging
API_KEY=staging-api-key
NODE_ENV=stagingenvx provides seamless integration with nodemon for development with auto-reload functionality.
# Zero-setup auto-reload development
npx --package=@href00/envx envx-nodemon server.js --env=dev
# With additional nodemon options
npx --package=@href00/envx envx-nodemon server.js --env=dev -- --watch src --ext js,mjs,json
# Different environments with auto-reload
npx --package=@href00/envx envx-nodemon server.js --env=staging
npx --package=@href00/envx envx-nodemon server.js --env=prod --allow-prod| Feature | envx | dotenv | dotenv-cli | env-var |
|---|---|---|---|---|
| Code modification required | β None | β Yes | β None | β Yes |
| Project installation needed | β No | β Yes | β Yes | β Yes |
| Works with legacy projects | β Perfect | β No | β Limited | β No |
| Environment overlays | β Built-in | β No | β No | β No |
| Nodemon integration | β Built-in | β Manual | β Manual | β Manual |
| Zero dependencies | β Yes | β Yes | β No | β No |
From dotenv:
// Before (requires code changes)
require('dotenv').config();
const app = require('./app');
// After (no code changes needed)
// Just run: npx @href00/envx app.js --env=dev
const app = require('./app'); // Same code!From dotenv-cli:
# Before
npm install dotenv-cli
dotenv -e .env.dev -- node app.js
# After
npx @href00/envx app.js --env=dev# Got a 5-year-old Node.js project that can't be touched?
npx @href00/envx old-app.js --env=production
# No refactoring needed!# Quick proof of concept - no setup time
npx @href00/envx prototype.js --env=dev# Show different environments instantly
npx @href00/envx demo.js --env=demo-client-a
npx @href00/envx demo.js --env=demo-client-b# Clean environment control in pipelines
npx @href00/envx deploy.js --env=staging --allow-ci# Consistent environment loading across services
npx @href00/envx user-service.js --env=dev
npx @href00/envx order-service.js --env=dev
npx @href00/envx payment-service.js --env=devAdd these scripts to your package.json:
{
"scripts": {
"dev": "npx --package=@href00/envx envx-nodemon server.js --env=dev",
"dev:staging": "npx --package=@href00/envx envx-nodemon server.js --env=staging",
"dev:debug": "npx --package=@href00/envx envx-nodemon server.js --env=dev -- --verbose",
"start": "npx --package=@href00/envx envx server.js --env=prod --allow-prod",
"test": "npx --package=@href00/envx envx test-runner.js --env=test"
}
}Alternative (if installed globally):
{
"scripts": {
"dev": "envx-nodemon server.js --env=dev",
"dev:staging": "envx-nodemon server.js --env=staging",
"dev:debug": "envx-nodemon server.js --env=dev -- --verbose",
"start": "envx server.js --env=prod --allow-prod",
"test": "envx test-runner.js --env=test"
}
}Then run:
npm run dev # Development with auto-reload
npm run dev:staging # Staging with auto-reload
npm run start # Production without auto-reload
npm test # Test environment# Watch specific directories
npx --package=@href00/envx envx-nodemon server.js --env=dev -- --watch src --watch config
# Custom file extensions
npx --package=@href00/envx envx-nodemon server.js --env=dev -- --ext js,mjs,ts,json
# Delay restart (useful for compilation)
npx --package=@href00/envx envx-nodemon server.js --env=dev -- --delay 2.5
# Ignore files/directories
npx --package=@href00/envx envx-nodemon server.js --env=dev -- --ignore tests/ --ignore docs/
# Environment file watching
npx --package=@href00/envx envx-nodemon server.js --env=dev -- --watch .env*Project Structure:
my-app/
βββ .env # Base config
βββ .env.dev # Development overrides
βββ .env.staging # Staging overrides
βββ .env.prod # Production config
βββ server.js # Your application
βββ package.json # Scripts and dependencies
βββ nodemon.json # Nodemon configuration (optional)
Environment Files:
# .env (base)
DATABASE_URL=postgresql://localhost:5432/myapp
PORT=3000
NODE_ENV=development
# .env.dev (development)
DATABASE_URL=postgresql://localhost:5432/myapp_dev
PORT=3001
DEBUG=true
LOG_LEVEL=debug
# .env.staging (staging)
DATABASE_URL=postgresql://staging-db:5432/myapp_staging
PORT=3002
NODE_ENV=staging
LOG_LEVEL=warn
# .env.prod (production)
DATABASE_URL=postgresql://prod-db:5432/myapp_production
PORT=3000
NODE_ENV=production
LOG_LEVEL=errorDevelopment Workflow:
# Start development with auto-reload
npm run dev
# β Loads .env + .env.dev
# β Starts server on port 3001
# β Auto-reloads on file changes
# β Debug logging enabled
# Test staging environment
npm run dev:staging
# β Loads .env + .env.staging
# β Starts server on port 3002
# β Auto-reloads on file changes
# β Staging database connection
# Production deployment
npm start
# β Loads .env + .env.prod
# β Starts server on port 3000
# β No auto-reload
# β Minimal logging- Base Loading: Always loads
.envfirst (if exists) - Overlay Loading: Loads environment-specific file (
.env.<env>) which overrides base values - Environment Injection: Sets all variables in
process.env - App Execution: Runs your application with the loaded environment
- CI Protection: Automatically skips file loading in CI environments (unless
--allow-ci) - Production Protection: Skips file loading when
NODE_ENV=production(unless--allow-prod) - Argument Passing: Cleanly passes arguments to your application via
-- - Error Handling: Graceful fallback when environment files don't exist
# Run automated tests
npm test
# Manual testing with different environments
npm run test:manual- Size: < 50KB unpacked
- Dependencies: Zero runtime dependencies
- Node.js: >= 14.0.0
- License: MIT
- Downloads: Growing daily! π
- dotenv - Original .env file loader
- dotenv-cli - CLI for dotenv
- nodemon - Auto-restart development tool
Contributions welcome! Please read our contributing guidelines and submit pull requests to our repository.
MIT - see LICENSE file for details.
Made with β€οΈ for developers who value simplicity
"Environment variables without the hassle" - that's the envx promise!