envelope-env
v1.0.1
Published
Organise multiple environments in /env and compile into root .env by name
Downloads
183
Maintainers
Readme
Envelope 📨
Envelope is a CLI tool that compiles a .env file from a set of environment-specific configurations. Organise your environment variables in an env/ directory and switch between them by name.
Installation
Global Installation
npm install -g envelope-envUsage
envelope use <environment>Project Structure
Envelope expects your project to have an env/ directory containing your environment configurations. Two layouts are supported, but they cannot be mixed in the same project.
Directory Mode
your-project/
├── env/
│ ├── .env # Common variables (shared across all envs)
│ ├── development/
│ │ └── .env # Development-specific variables
│ ├── staging/
│ │ └── .env # Staging-specific variables
│ └── production/
│ └── .env # Production-specific variables
├── .env # Compiled by running `envelope use <environment>`
└── ...Flat Mode
your-project/
├── env/
│ ├── .env # Common variables (shared across all envs)
│ ├── .env.development # Development-specific variables
│ ├── .env.staging # Staging-specific variables
│ └── .env.production # Production-specific variables
├── .env # Compiled by running `envelope use <environment>`
└── ...Usage
Commands
envelope list
List all available environments in your project.
envelope listOutput:
Available environments: development, staging, productionenvelope get <environment>
Display the compiled environment variables for a specific environment without writing to file.
envelope get development
envelope get production --silentOptions:
--silent, -s- Suppress status messages
envelope use <environment>
Compile and write environment variables for a specific environment to your project's .env file.
envelope use development
envelope use production --silentOptions:
--silent, -s- Suppress status messages
envelope current
Print the currently active environment (reads ENVELOPE_ENV from the compiled .env file).
envelope currentExamples
Setting up a new environment
- Create your environment directory:
mkdir -p env/staging- Create environment-specific variables:
# env/staging/.env
DATABASE_URL=postgresql://staging:pass@localhost:5432/staging_db
API_URL=https://staging-api.example.com
LOG_LEVEL=debug- Use the environment:
envelope use stagingViewing environment variables
# View development environment variables
envelope get development
# View production environment variables silently
envelope get production --silentEnvironment File Format
Environment files follow standard .env format:
# Comments start with #
DATABASE_URL=postgresql://localhost:5432/mydb
API_KEY=your-secret-key
DEBUG=true
# Empty lines are allowed
# Variables can contain spaces and special characters
COMPLEX_VALUE="This is a complex value with spaces"Environment Variable Precedence
When compiling environment variables, Envelope follows this order:
- Base variables -
ENVELOPE_ENVandENVELOPE_DIRare always set automatically - Common variables - From
env/.env(if it exists) - Environment-specific variables - From
env/<environment>/.envorenv/.env.<environment>
Environment-specific variables will override common variables with the same name.
Development
Building
npm run buildDevelopment Mode
npm run devTesting
npm testContributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
