@raphaellcs/env-manager
v1.0.0
Published
Manage environment variables with ease
Maintainers
Readme
@raphaellcs/env-manager
A simple and powerful tool for managing environment variables with ease.
Features
- 📋 List all environment variables
- 🔍 Get specific variables
- ✏️ Set new variables
- 🗑️ Remove variables
- 📄 Validate environment file format
- 📋 Copy variables between files
- 🔒 Mask sensitive values by default
Installation
# Use with npx (no installation needed)
npx @raphaellcs/env-manager --help
# Or install globally
npm install -g @raphaellcs/env-managerUsage
List Environment Variables
# List all variables from .env file
npx @raphaellcs/env-manager list
# List from custom file
npx @raphaellcs/env-manager list --file config.env
# Include system environment variables
npx @raphaellcs/env-manager list --allGet a Specific Variable
# Get a variable
npx @raphaellcs/env-manager get DB_HOST
# Get from custom file
npx @raphaellcs/env-manager get API_KEY --file .env.production
# Show raw value without masking
npx @raphaellcs/env-manager get PASSWORD --rawSet a Variable
# Set a new variable
npx @raphaellcs/env-manager set DB_HOST localhost
# Set in custom file
npx @raphaellcs/env-manager set NODE_ENV production --file .env.productionRemove a Variable
# Remove a variable
npx @raphaellcs/env-manager unset DB_HOST
# Remove from custom file
npx @raphaellcs/env-manager unset API_KEY --file .env.testInitialize .env File
# Create a new .env file with template
npx @raphaellcs/env-manager init
# Create with custom name
npx @raphaellcs/env-manager init --file .env.exampleCopy Variables Between Files
# Copy from .env.example to .env
npx @raphaellcs/env-manager copy .env.example .env
# Copy and overwrite existing variables
npx @raphaellcs/env-manager copy .env.example .env --overwriteValidate Environment File
# Validate .env file
npx @raphaellcs/env-manager validate
# Validate custom file
npx @raphaellcs/env-manager validate --file .env.productionExamples
Example 1: List All Variables
$ npx @raphaellcs/env-manager list
📋 Environment Variables (.env):
DB_HOST = lo****st
DB_PORT = 54****
DB_NAME = my**
DB_USER = po*******e
DB_PASSWORD = pa******re
$ npx @raphaellcs/env-manager list --all
📋 Environment Variables (.env):
DB_HOST = lo****st
DB_PORT = 54****
System Environment Variables:
NODE_ENV = de********ent
HOME = /h**e/lExample 2: Create and Set Variables
$ npx @raphaellcs/env-manager init
✓ Created .env
Edit the file and add your environment variables.
$ npx @raphaellcs/env-manager set DB_HOST localhost
✓ Set DB_HOST successfully
$ npx @raphaellcs/env-manager set API_KEY secret123
✓ Set API_KEY successfullyExample 3: Get Variables
$ npx @raphaellcs/env-manager get DB_HOST
localhost
$ npx @raphaellcs/env-manager get API_KEY
se****23
$ npx @raphaellcs/env-manager get API_KEY --raw
secret123Example 4: Validate File
$ npx @raphaellcs/env-manager validate
✔ File is valid
$ npx @raphaellcs/env-manager validate
Line 5: Missing '=' separator
Line 8: Spaces in key name
⚠ File is valid with 1 error(s) and 1 warning(s)Example 5: Copy Variables
$ npx @raphaellcs/env-manager copy .env.example .env
✓ Copied 8 variable(s) to .env
$ npx @raphaellcs/env-manager copy .env.example .env --overwrite
✓ Copied 12 variable(s) to .envBest Practices
1. Never Commit .env Files
Add .env to your .gitignore:
.env
.env.local
.env.*.local2. Use .env.example
Create a template file:
npx @raphaellcs/env-manager init --file .env.exampleCommit this file so others know which variables are needed.
3. Use Different Files for Different Environments
# Development
.env
# Staging
.env.staging
# Production
.env.production4. Reference Variables in Code
// In Node.js
require('dotenv').config();
const dbHost = process.env.DB_HOST;
const apiKey = process.env.API_KEY;Security Tips
- ❌ Never commit
.envfiles - ✅ Use
.env.exampleas a template - 🔒 Rotate sensitive keys regularly
- 📋 Use different files for different environments
- 🚫 Don't include
.envin backups - 🔑 Use strong passwords and keys
Common Use Cases
Development Setup
# 1. Create .env.example
npx @raphaellcs/env-manager init --file .env.example
# 2. Team member creates their own .env
npx @raphaellcs/env-manager init
# 3. Set variables
npx @raphaellcs/env-manager set DB_HOST localhost
npx @raphaellcs/env-manager set NODE_ENV developmentDeployment
# 1. Copy from example to production
npx @raphaellcs/env-manager copy .env.example .env.production
# 2. Set production values
npx @raphaellcs/env-manager set NODE_ENV production --file .env.production
npx @raphaellcs/env-manager set API_KEY production_key --file .env.production
# 3. Validate before deploy
npx @raphaellcs/env-manager validate --file .env.productionConfiguration Management
# Check current configuration
npx @raphaellcs/env-manager list
# Verify specific values
npx @raphaellcs/env-manager get DB_HOST
# Update configuration
npx @raphaellcs/env-manager set DB_PORT 5432
# Remove unused variables
npx @raphaellcs/env-manager unset DEBUGContributing
Contributions are welcome! Feel free to open an issue or submit a pull request.
License
MIT
Author
Dream Heart 🌙
