Environment file encryption and management tool for secure development workflows.
EnvX is a command-line tool that helps you securely manage environment files across different stages (development, staging, production) using GPG encryption. It provides a simple workflow for encrypting sensitive environment variables while maintaining ease of use for development teams.
- π GPG-based encryption for maximum security
- π― Stage-based management (development, staging, production, etc.)
- π Interactive setup with guided configuration
- π Batch operations on multiple files and directories
- π Secret management with
.envrc
integration - π¨ Beautiful CLI with colored output and progress indicators
- π‘οΈ Best practices enforcement and security recommendations
Before using EnvX, ensure you have:
- Node.js >= 14.0.0
- GPG (GNU Privacy Guard) installed and configured
brew install gnupg
sudo apt-get install gnupg
Download from https://gnupg.org/download/
gpg --version
npm install -g envx-cli
npm install envx-cli
npx envx --help
- Initialize EnvX in your project:
envx init
- Create environment files:
envx create -e development
envx create -e production
- Set up secrets for encryption:
envx interactive
- Encrypt your environment files:
envx encrypt -e production
- Commit encrypted files to git:
git add *.gpg
git commit -m "Add encrypted environment files"
- Copy environment to .env for use:
envx copy -e production
- Decrypt when needed:
envx decrypt -e production
Initialize EnvX in a new project with guided setup.
envx init
Create new environment files.
# Create a single environment file
envx create -e development
# Interactive mode for multiple environments
envx create -i
# Use a template file
envx create -e production -t .env.example
# Overwrite existing files
envx create -e staging --overwrite
Options:
-e, --environment <env>
- Environment name-t, --template <path>
- Template file path-i, --interactive
- Interactive mode--overwrite
- Overwrite existing files-c, --cwd <path>
- Working directory
Encrypt environment files using GPG.
# Encrypt specific environment
envx encrypt -e production
# Encrypt all environments at once
envx encrypt --all
# Use custom secret from .envrc
envx encrypt -e production -s CUSTOM_SECRET
# Interactive file selection (for single environment)
envx encrypt -e staging -i
# Encrypt all with specific passphrase
envx encrypt --all -p "your-passphrase"
# Specify passphrase directly (not recommended)
envx encrypt -e development -p "your-passphrase"
Options:
-e, --environment <env>
- Environment name (required unless using --all)-a, --all
- Process all available environments-p, --passphrase <pass>
- Encryption passphrase-s, --secret <secret>
- Secret variable name from .envrc-i, --interactive
- Interactive file selection (disabled with --all)-c, --cwd <path>
- Working directory
Decrypt environment files.
# Decrypt specific environment
envx decrypt -e production
# Decrypt all environments at once
envx decrypt --all
# Overwrite existing files without confirmation
envx decrypt -e development --overwrite
# Decrypt all with overwrite flag
envx decrypt --all --overwrite
# Interactive file selection (for single environment)
envx decrypt -e staging -i
Options:
-e, --environment <env>
- Environment name (required unless using --all)-a, --all
- Process all available environments-p, --passphrase <pass>
- Decryption passphrase-s, --secret <secret>
- Secret variable name from .envrc-i, --interactive
- Interactive file selection (disabled with --all)--overwrite
- Overwrite existing files without confirmation-c, --cwd <path>
- Working directory
Interactive setup for .envrc
file with secrets.
# Start interactive setup
envx interactive
# Overwrite existing .envrc
envx interactive --overwrite
# Generate random secrets for all environments
envx interactive --generate
Options:
--overwrite
- Overwrite existing .envrc file--generate
- Generate random secrets-c, --cwd <path>
- Working directory
List all environment files and their status.
# List all environment files
envx list
# Short alias
envx ls
Options:
-c, --cwd <path>
- Working directory
Copy environment file from a specific stage to .env
. This command is perfect for deployment scenarios where you need to activate a specific environment configuration.
# Copy production environment to .env (single directory)
envx copy -e production
# Copy to ALL directories with environment files (multi-service)
envx copy -e production --all
# Copy development environment to .env
envx copy -e development
# Copy with overwrite (no confirmation)
envx copy -e staging --overwrite
# Copy from encrypted file (auto-decrypts)
envx copy -e production -p "your-passphrase"
# Use secret from .envrc for encrypted files
envx copy -e production -s PRODUCTION_SECRET
# Copy production to all services from project root
envx copy -e production --all --overwrite
Options:
-e, --environment <env>
- Environment name (required)-a, --all
- Process all directories with environment files-p, --passphrase <pass>
- Passphrase for decryption (if source is encrypted)-s, --secret <secret>
- Secret variable name from .envrc--overwrite
- Overwrite existing .env file without confirmation-c, --cwd <path>
- Working directory
How it works:
- Single directory mode: Copies
.env.<environment>
to.env
in current directory - Multi-directory mode (
--all
): Finds all directories with environment files and copies to each - If
.env.<environment>
exists (unencrypted), it copies directly to.env
- If
.env.<environment>.gpg
exists (encrypted), it decrypts and copies to.env
- Prefers unencrypted files over encrypted ones if both exist
- Creates backup of existing
.env
file during encrypted operations - Shows security warnings when copying production environments
Show project encryption status and recommendations.
envx status
Options:
-c, --cwd <path>
- Working directory
- Create environment files:
envx create -e development
envx create -e production
- Edit your environment files:
# Edit .env.development
echo "DATABASE_URL=postgresql://localhost:5432/myapp_dev" >> .env.development
echo "API_KEY=dev-api-key" >> .env.development
# Edit .env.production
echo "DATABASE_URL=postgresql://prod-server:5432/myapp" >> .env.production
echo "API_KEY=prod-api-key-secret" >> .env.production
- Set up encryption secrets:
envx interactive
- Encrypt production secrets:
envx encrypt -e production
- Copy environment for application use:
# For development
envx copy -e development
# For production deployment
envx copy -e production
- Add to version control:
echo ".env.*" >> .gitignore
echo "!*.gpg" >> .gitignore
git add .env.production.gpg .envrc
git commit -m "Add encrypted production environment"
- Single service deployment:
# On production server after pulling latest code
envx copy -e production --overwrite
- Multi-service deployment (from project root):
# Copy production environment to ALL services at once
envx copy -e production --all --overwrite
- For local development with production data:
# Copy production environment locally (be careful!)
envx copy -e production
# Or copy to all services locally
envx copy -e production --all
- Switch between environments easily:
# Use development environment across all services
envx copy -e development --all --overwrite
# Switch to staging across all services
envx copy -e staging --all --overwrite
# Switch to production (with warning)
envx copy -e production --all --overwrite
- Clone repository and set up environment:
git clone <your-repo>
cd <your-repo>
# For development
envx copy -e development
# For production deployment
envx copy -e production
- Make changes and re-encrypt:
# Edit .env.production directly or copy from .env after changes
cp .env .env.production # if you made changes to .env
envx encrypt -e production
git add .env.production.gpg
git commit -m "Update production configuration"
From project root, manage all services at once:
# Copy production environment to all services
envx copy -e production --all
# Copy staging environment to all services
envx copy -e staging --all --overwrite
# Perfect for deployment scripts
#!/bin/bash
envx copy -e production --all --overwrite
docker-compose up -d
Process all environments at once:
# Encrypt all environment files
envx encrypt --all
# Decrypt all environment files
envx decrypt --all
# Decrypt all with overwrite protection disabled
envx decrypt --all --overwrite
Benefits of using --all
:
- β Efficiency: Process multiple environments in one command
- β Consistency: Same passphrase/secret handling across all environments
- β Automation: Perfect for CI/CD pipelines and scripts
- β Safety: Each environment is processed independently - failures in one don't stop others
- β Reporting: Comprehensive summary showing results for each environment
Key Features of --all
Flag:
- Sequential Processing: Environments are processed one by one to avoid resource conflicts
- Independent Operations: Failure in one environment doesn't stop processing of others
- Smart Passphrase Resolution: Uses provided passphrase, environment-specific secrets, or prompts as needed
- Comprehensive Reporting: Shows detailed results for each environment plus overall summary
- Safety Checks: Validates compatibility with other flags (incompatible with
--environment
and--interactive
) - Flexible Configuration: Works with all existing options like
--passphrase
,--secret
,--cwd
, and--overwrite
Activate environments for your application:
# Activate development environment for local work
envx copy -e development
# Activate staging for testing
envx copy -e staging --overwrite
# Activate production for deployment
envx copy -e production --overwrite
Use cases for envx copy
:
- π Deployment: Copy environment configuration to
.env
for application use - π Environment Switching: Quickly switch between different configurations
- π οΈ Local Development: Use production/staging config locally for debugging
- π¦ Docker/Containers: Set up environment in containerized deployments
- π§ CI/CD: Activate specific environments during pipeline stages
- ποΈ Multi-Service: Manage environment files across multiple services from project root
- β‘ Batch Operations: Copy same environment to all services with one command
EnvX uses .envrc
files to store encryption secrets. The format follows the direnv convention:
# Environment secrets generated by envx
export DEVELOPMENT_SECRET="your-development-secret"
export STAGING_SECRET="your-staging-secret"
export PRODUCTION_SECRET="your-production-secret"
EnvX follows the convention: <STAGE>_SECRET
Examples:
DEVELOPMENT_SECRET
STAGING_SECRET
PRODUCTION_SECRET
LOCAL_SECRET
your-project/
βββ .env.development # Unencrypted (local only)
βββ .env.staging.gpg # Encrypted (committed)
βββ .env.production.gpg # Encrypted (committed)
βββ .envrc # Secrets (local only)
βββ .gitignore # Excludes .env.* but allows *.gpg
- β Always encrypt production and staging environment files
- β
Commit encrypted
.gpg
files to version control - β
Add
.envrc
to your.gitignore
- β Use strong, unique secrets for each environment
- β Regularly rotate encryption secrets
- β
Use
envx status
to check your security posture
- β Never commit unencrypted
.env.*
files (except templates) - β Don't commit
.envrc
files to version control - β Don't use weak or predictable passphrases
- β Don't share secrets through insecure channels
- β Don't leave decrypted files in production environments
# Environment files
.env.*
!.env.example
!.env.template
!*.gpg
# EnvX secrets
.envrc
EnvX works great with direnv for automatic environment loading:
- Install direnv:
# macOS
brew install direnv
# Ubuntu/Debian
sudo apt install direnv
- Add to your shell profile:
# For bash
echo 'eval "$(direnv hook bash)"' >> ~/.bashrc
# For zsh
echo 'eval "$(direnv hook zsh)"' >> ~/.zshrc
- Allow direnv in your project:
direnv allow
Now your secrets will be automatically loaded when you enter the project directory!
Problem: gpg: command not found
# Install GPG (see Prerequisites section)
Problem: gpg: decryption failed: Bad session key
# Wrong passphrase - try again or check your .envrc file
envx decrypt -e production
Problem: gpg: can't connect to the agent
# Restart GPG agent
gpgconf --kill gpg-agent
gpgconf --launch gpg-agent
Problem: EACCES: permission denied
# Check file permissions
ls -la .env.*
chmod 644 .env.*
Problem: Template file not found
# Check if template exists
ls -la .env.example
# Or create without template
envx create -e development
EnvX respects the following environment variables:
ENVX_DEFAULT_CWD
- Default working directoryENVX_GPG_BINARY
- Custom GPG binary pathNODE_ENV
- Affects error reporting verbosity
0
- Success1
- General error2
- Invalid arguments3
- File operation failed4
- GPG operation failed
EnvX includes a streamlined test suite focused on essential functionality and real-world CLI usage scenarios.
# Run all tests
npm test
# Run core functionality tests
npm run test:core
# Run integration tests
npm run test:integration
# Run tests with coverage
npm run test:coverage
# Run tests in watch mode (for development)
npm run test:watch
The test suite prioritizes essential functionality over comprehensive coverage:
- β Core business logic - Command validation, file utilities, path manipulation
- β Real CLI scenarios - Actual command execution in various environments
- β Critical workflows - User-facing functionality that must work reliably
- β UI/cosmetic features - Colors, formatting, and visual elements
- β Complex mocking - Simplified approach focusing on actual behavior
Current Status: β 120 tests passing, ~11s execution time
-
Core Tests: 104 tests covering essential functionality
- Schema validation: 25 tests (command input validation)
- File utilities: 39 tests (path manipulation, secret generation)
- Command logic: 25 tests (workflow patterns and decision logic)
- All-flag functionality: 15 tests (batch operations, error handling)
-
Integration Tests: 16 tests covering real CLI usage
- Help/version commands
- Create command functionality
- All-flag compatibility testing
- Error handling scenarios
- Environment validation
__tests__/
βββ core/ # Essential functionality tests
β βββ schemas.test.ts # Input validation for all commands
β βββ file.test.ts # File utilities and path manipulation
β βββ commands.test.ts # Command workflow logic patterns
β βββ all-flag.test.ts # Batch operations and --all flag functionality
βββ integration/ # End-to-end CLI tests
βββ cli.test.ts # Real CLI execution scenarios
For detailed testing information, see TESTING.md.
git clone https://github.com/rahulretnan/envx-cli
cd envx-cli
npm install
npm run build
npm link
# Start development mode
npm run dev
# Run tests in watch mode
npm run test:watch
# Build and test
npm run build && npm test
- Fork the repository
- Create a feature branch:
git checkout -b feature-name
- Make your changes and add tests
- Run tests:
npm test
- Ensure test coverage remains high:
npm run test:coverage
- Submit a pull request
- New CLI commands must include integration tests
- Core utility functions must include unit tests
- Focus on user-facing functionality over implementation details
- Keep tests simple and maintainable
- Ensure tests verify real CLI behavior
See CHANGELOG.md for detailed release notes.
MIT Β© rahulretnan
- π Issues
- π¬ Discussions
- π§ Email: hi@rahulretnan.me
Made with β€οΈ by developers, for developers.
Remember: Security is not a feature, it's a requirement. EnvX helps you maintain security without sacrificing developer experience.