ask-env
v0.0.2
Published
CLI to interactively setup and manage .env files. Prompt users for environment variable values and automatically update configuration files.
Maintainers
Readme
ask-env
A CLI tool to interactively setup and manage .env files. Prompt users for environment variable values and automatically update your configuration files.
Features
- 🎯 Interactive prompts for environment variables
- ✨ Support for required and optional variables
- 📝 Automatic
.envfile creation and updates - 🔄 Preserve existing values when prompting
- 📁 Customizable file path support
- 🚀 Simple and intuitive CLI interface
Installation
npm install -g ask-env
# or
pnpm add -g ask-env
# or
yarn global add ask-envUsage
Basic Usage
Prompt for a single environment variable:
ask-env API_KEYPrompt for multiple environment variables:
ask-env API_KEY DATABASE_URL PORTSpecify Custom File
By default, ask-env edits the .env file in the current directory. You can specify a different file using the -f or --file option:
ask-env API_KEY -f .env.local
ask-env API_KEY DATABASE_URL --file .env.productionVariable Types
Required Variables
Variables are required by default. Users must provide a value:
ask-env API_KEYOptional Variables
Prefix the variable name with ?: to make it optional:
ask-env '?:DEBUG_MODE' '?:LOG_LEVEL'Custom Prompts
You can customize the prompt message by using the format message:param:name:
ask-env 'url for:!:API_URL' 'optional email for:?:ADMIN_EMAIL'- The first part is the message displayed to the user
- The second part is the parameter type:
!for required,?for optional - The third part is the actual environment variable name
Examples:
# Custom message with required variable
ask-env 'Please enter your API key:!:API_KEY'
# Custom message with optional variable
ask-env 'Enter your email (optional):?:ADMIN_EMAIL'How It Works
ask-envreads the existing.envfile (if it exists)- For each variable specified, it prompts the user for a value
- If a value already exists in the
.envfile, it's shown as the default - New or changed values are written back to the file
- Values that remain unchanged are not modified
Examples
Example 1: Setup Development Environment
ask-env 'Database URL:!:DATABASE_URL' 'Redis URL:!:REDIS_URL' 'Debug mode:?:DEBUG'This will prompt for DATABASE_URL and REDIS_URL (required), and DEBUG (optional).
Example 2: Update Production Config
ask-env API_KEY PRODUCTION_URL --file .env.productionExample 3: Initialize New Project
ask-env \
'Application name:!:APP_NAME' \
'Port:!:PORT' \
'Database URL:!:DATABASE_URL' \
'Secret key:!:SECRET_KEY' \
'Debug mode:?:DEBUG'Development
Install Dependencies
npm installRun Tests
npm testManual Testing
# Test with required variables
node index.js TEST TEST2 -f .env.local
# Test with mixed required/optional variables
node index.js 'url for:TEST' 'optionalurl for:?:TEST3' TEST2 -f .env.localLicense
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
