A CLI tool for managing environment variables
To install convert-json-env
you can use yarn
, npm
, brew
, wget
, apt-get
.
yarn global add clienv
# or
npm install --global clienv
# or
brew install clienv
# or
wget install clienv
# or
apt-get install clienv
- convert - convert environment variable file/format to another
clienv convert --file=example.json --out=.env.local
e.g json to .env yaml to json 2. log - show env values in terminal 3. validate - validate env values against a schema
NODE.js - .env.local -> .env.development -> .env -> config/local.json -> config/development.json
$ cat example-firebaseConfig.json
{
"apiKey": "abcdefghijklmnopqrstuvwxyz1234567890ABC",
"authDomain": "myapp-1234a.firebaseapp.com",
"databaseURL": "https://myapp-1234a.firebaseio.com",
"projectId": "myapp-1234a",
"storageBucket": "myapp-1234a.appspot.com",
"messagingSenderId": "123456789012",
"appId": "1:234567890124:web:1234567890abcdef"
}
$ convert-json-env example-firebaseConfig.json --prefix="export "
✅ example-firebaseConfig.env created.
$ cat example-firebaseConfig.env
export apiKey='abcdefghijklmnopqrstuvwxyz1234567890ABC'
export authDomain='myapp-1234a.firebaseapp.com'
export databaseURL='https://myapp-1234a.firebaseio.com'
export projectId='myapp-1234a'
export storageBucket='myapp-1234a.appspot.com'
export messagingSenderId='123456789012'
export appId='1:234567890124:web:1234567890abcdef'
$ clienv convert example-firebaseConfig.json --out=.local.env --prefix=VUE_APP_
.local.env created.
$ cat .env.local
VUE_APP_apiKey='abcdefghijklmnopqrstuvwxyz1234567890ABC'
VUE_APP_authDomain='myapp-1234a.firebaseapp.com'
VUE_APP_databaseURL='https://myapp-1234a.firebaseio.com'
VUE_APP_projectId='myapp-1234a'
VUE_APP_storageBucket='myapp-1234a.appspot.com'
VUE_APP_messagingSenderId='123456789012'
VUE_APP_appId='1:234567890124:web:1234567890abcdef'
In this case, no files are output.
$ clienv convert firebaseConfig.json --prefix=process.env.VUE_APP_ --embed
{
apiKey: process.env.VUE_APP_apiKey,
authDomain: process.env.VUE_APP_authDomain,
databaseURL: process.env.VUE_APP_databaseURL,
projectId: process.env.VUE_APP_projectId,
storageBucket: process.env.VUE_APP_storageBucket,
messagingSenderId: process.env.VUE_APP_messagingSenderId,
appId: process.env.VUE_APP_appId
}
{
"scripts": {
"check-env": "clienv check -s .env.schema -e .env.local",
// Execute the check-env before starting your application
"dev": "npm run check-env && next dev"
}
}
You can customize the cli options. Here you have the possible customizations:
Sets the custom file to be used as a schema/base file. This is the file which is used to sync the environment file
# Set a custom schema (file to be based on)
dotenv-checker --schema .env.base
Sets the custom file to be synchronized with the schema file.
In case this file is out-of-sync and has some keys that the schema doesn't have, it reports the named keys to you through terminal
# File to check that needs to be in sync with schema file
dotenv-checker --env .env.local
By default it auto create the environment file if it doesn't exist. If you set this to "false" you can force to be asked to create it or not in case it's needed
# File to check that needs to be in sync with schema file
dotenv-checker --skip-create-question=false
By default it auto updates the environment file if it differs from schema file. If you set this to "false" you can force to be asked to update it or not in case it's needed
# File to check that needs to be in sync with schema file
dotenv-checker --skip-update-question=false
Created with Typescript! ⚡ and latin music 🎺🎵
`
usage:
\tclienv convert <input.file> <out.file> [options]
\tclienv convert --file=config.json --prefix="export "
\tclienv convert --file=config.json --prefix="NEXT_PUBLIC_"
\tclienv convert --file=.env.local --out=config.json
\tclienv convert --file=.env.local --out=config.json --embed=VUE_APP_
\tclienv log <env.variable> [options]
\tclienv log MONGO_URL --file=".env.local"
\tclienv log --log=MONGO_URL" --file=".env.local"
\tclienv log --log=MONGO_URL --file=".env.local" --out=echo
Options:
\t--out\t\tthe output file path.
\t--prefix\t\tthe prefix of environment variables in env file
\t--suffix\t\tthe suffix of environment variables in env file
\t--embed\t\tthe suffix of environment variables in env file