Convert dotenv file or/and container env vars to a Javascript Object saved into file
6.3K
abdennour/dotenv-to-js-object is a software which convert environment variable in a Javascript Object format saved into a destination file
The source of the environment variable can be :
-s=<VALUE> or --src=<VALUE> option--env-vars flag. If you don't provide -s or --src option, --env-vars flag will be forced.# create .env file with one entry
echo "REACT_APP_API=http://localhost:8080" > .env.example
# make alias of the software
alias dotenv-to-js='docker run -v $(pwd):/data -w /data -e MSG="Hello" abdennour/dotenv-to-js-object'
# run common script, then :
dotenv-to-js
# Validate
### A new file "env.js" must be created
### it must include env vars of the container process
Without no argument, the source of env vars is the process env vars.
--src# run common script, then :
dotenv-to-js --src=.env.example
# Validate
### A new file "env.js" must be created
### it must include '.... = { REACT_APP_API: "http://localhost:8080" '}
--env-vars# run common script, then :
dotenv-to-js --src=.env.example --env-vars
# Validate
### A new file "env.js" must be created
### it must include '.... = { REACT_APP_API: "http://localhost:8080" ', .... , MSG: 'Hello'}
Even though MSG is not in the .env file, it has been rendered because it's a container/process env var and --env-vars flag has been used
# run common script, then :
dotenv-to-js --src=.env.example --dest=assets/js
# Validate
### A new directory must be created under ./assets/js/
### A new file "env.js" must be created inside this directory (./assets/js/)
### env.js must include the expected content
--run-asBy default this software convert env vars, then it terminates.
This is because the default value of --run-as option is job.
If you want to run it as daemon, you need to specify --run-as=daemon
# run common script, then :
dotenv-to-js --src=.env.example --run-as=daemon
# Validate
### The process must not finish unless you type Ctrl+C
### Also open another terminal, edit .env.example file.
### Then check env.js file ==> it must be refreshed
--refresh-period--refresh-period is a number and its unit is second
# run common script, then :
dotenv-to-js --src=.env.example \
--run-as=daemon \
--refresh-period=100
# Validate
### The process must not finish unless you type Ctrl+C
### Refershing the env.js file is done every 100 seconds
--env-vars-filter# run common script, then :
dotenv-to-js --env-vars-filter=REACT_APP_ --src=.env.example
# Validate
### env.js must be created
### If any, only env vars contains REACT_APP_ will be added to env.js
Content type
Image
Digest
Size
2.7 MB
Last updated
over 5 years ago
docker pull abdennour/dotenv-to-js-object