envar-cli is lightweight global package for managing .env variables using cli. You can add, update, remove or list environment variables.
# with npm
npm install -g envar-cli
Open your terminal on project folder and check the below instructions. To get help please write envar-cli --help on terminal.
There are several .env file extension. Default file is .env for envar-cli.
envar-cli supports:
- .env
- .env.example
- .env.local
- .env.dev
- .env.development
- .env.prod
- .env.production
- .env.staging
- .env.preview
Please specify the extension end of the command with --[fileSpecifier]
envar-cli [command] [value] [extension]
# Select .env (do not write anything)
#.env is default. No need to write anything.
# .env.example
envar-cli [command] [value] --example
# .env.local
envar-cli [command] [value] --local
# .env.dev
envar-cli [command] [value] --dev
# .env.development
envar-cli [command] [value] --development
# .env.prod
envar-cli [command] [value] --prod
# .env.production
envar-cli [command] [value] --production
# .env.staging
envar-cli [command] [value] --staging
# .env.preview
envar-cli [command] [value] --preview
If .env file is not exists envar-cli will create a blank .env file.
envar-cli add "PORT=9000"
# or
envar-cli add PORT=9000
#with specific .env file --[extension]
envar-cli add PORT=3000 --dev
envar-cli add PORT=8080 --prod
.env:
PORT=9000
.env.dev:
PORT=3000
.env.prod:
PORT=8080
If you want to add a comment to your .env file, please use --comment option. It will be add your comment line before the variable. Currently, it works only if variable is newly added.
envar-cli add "SECRET_KEY=github" --comment "# SECRET KEYS"
#or
#with specific .env file --[extension]
envar-cli add "SECRET_KEY=google" --comment "# SECRET KEYS" --prod
.env:
# SECRET KEYS
SECRET_KEY=github
.env.prod:
# SECRET KEYS
SECRET_KEY=google
To update a variable you can use update command.
envar-cli update SECRET_KEY=github
#or
envar-cli update "SECRET_KEY=github"
#with specific .env file --[extension]
envar-cli update SECRET_KEY=github --prod
If variable not exists you will see a message like this: ❗: <MY_VAR> not found in .env
Deleting is also simple. Just use remove, del or delete command. And please:
- Write only variable name not with value.
- Pay attention to case sensitivity
envar-cli remove SECRET_KEY
#or
envar-cli del "SECRET_KEY"
#with specific .env file --[extension]
envar-cli delete SECRET_KEY --staging
To count and see your environment values please use list command.
envar-cli list
#with specific .env file --[extension]
envar-cli list --development
1. PORT=8080
2. SECRET_KEY=github
📄 : 2 variables found in .env