Node.js package to work with `.env` files in the same way as docker and docker-compose via `--env-file` or `"env_file"` in package.json
MIT License
Node.js package to work with .env
files in the same way as docker and docker-compose via argument --env-file=…
in CLI, "env_file": […]
in package.json and environment variables ENV_FILE_?=…
npm install --save-dev arg-env
In addition, check the example of usage
See Node docs
node --require=arg-env index.js --env-file=1.env --env-file=2.env
# jest
node -r arg-env node_modules/.bin/jest --env-file=test.env
See npm docs
{
"config": {
"env_file": [
"3.env",
"./4.env"
]
},
"scripts": {
"start:dev": "node --require=arg-env index.js"
}
}
import { parse } from "arg-env"
All specifications are taken from output of actual docker run
COMMENTED=comment #ed
is resolved to comment
V1=val
,V2='val'
,V3="val"
are resolved to val
EXPR=${VAR1} and ${VAR2}
is resolved to value1 and value2
DEFAULT=${UNDEFINED:-val}
is resolved to val
Files are independent but rely on global environment
Files don’t overwrite global environment. Next file takes precedence over previous. In addition, files in package.json has less priority than in command line arguments.
Other env JS packages hasn't command-line and package interfaces, more-over, didn't behave like docker
: see details ./src/parse.spec.ts. Input is ./src/specs/input.env, output saved in ./src/specs/spec.json via ./src/specs/get.sh
.
Tool name | Quotes | Isolated | Inline comment | Reuse | Default value | Weird names | Error syntax | Var of Var |
---|---|---|---|---|---|---|---|---|
docker-compose |
' ,"
|
Yes | Yes | Yes | Yes | Yes | No | No |
arg-env |
' ,"
|
Yes | Yes | Yes | Yes | Yes | Not yet | Not yet |
dotenv |
' ,"
|
Yes | No | No | No | No | No | No |
dotenv-expand |
' ,"
|
No? | No | More | No | No | No | No |
dotenv-extended |
' ,"
|
No? | No | No | No | No | No | No |
envfile | No | - | No | No | No | Other | No | No |
Experiments with .env
stuff
./setup.sh
./prebuild.sh
./get_envs.sh
Envs list is taken from docker-compose/docker-compose.yml (service injected
) and written to docker/.env