Gathering detailed insights and metrics for dotenv-cli
Gathering detailed insights and metrics for dotenv-cli
Gathering detailed insights and metrics for dotenv-cli
Gathering detailed insights and metrics for dotenv-cli
npm install dotenv-cli
Fix security issue
Published on 21 Nov 2024
Forward signals to child process
Published on 07 May 2024
Fix bug with -p in 7.4.0
Published on 09 Mar 2024
Release better variable usage (`-v`)
Published on 07 Mar 2024
v7.3.0
Published on 17 Aug 2023
Allow --override
Published on 05 Apr 2023
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
516 Stars
110 Commits
51 Forks
3 Watching
3 Branches
29 Contributors
Updated on 21 Nov 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-17.8%
303,045
Compared to previous day
Last week
7.1%
1,700,882
Compared to previous week
Last month
14.8%
6,907,610
Compared to previous month
Last year
91.9%
57,073,476
Compared to previous year
4
1
NPM
1$ npm install -g dotenv-cli
Yarn
1$ yarn global add dotenv-cli
pnpm
1pnpm add -g dotenv-cli
1$ dotenv -- <command with arguments>
This will load the variables from the .env file in the current working directory and then run the command (using the new set of environment variables).
Alternatively, if you do not need to pass arguments to the command, you can use the shorthand:
1$ dotenv <command>
Another .env file could be specified using the -e flag (this will replace loading .env
file):
1$ dotenv -e .env2 -- <command with arguments>
Multiple .env files can be specified, and will be processed in order:
1$ dotenv -e .env3 -e .env4 -- <command with arguments>
Some applications load from .env
, .env.development
, .env.local
, and .env.development.local
(see #37 for more information).
dotenv-cli
supports this using the -c
flag for just .env
and .env.local
and -c development
for the ones above.
The -c
flag can be used together with the -e
flag. The following example will cascade env files located one folder up in the directory tree (../.env
followed by ../.env.local
):
1dotenv -e ../.env -c
It is possible to set variable directly from command line using the -v flag:
1$ dotenv -v VARIABLE=somevalue -- <command with arguments>
Multiple variables can be specified:
1$ dotenv -v VARIABLE1=somevalue1 -v VARIABLE2=somevalue2 -- <command with arguments>
Variables set up from command line have higher priority than from env files.
Purpose of this is that standard approach
VARIABLE=somevalue <command with arguments>
doesn't work on Windows. The -v flag works on all the platforms.
If you want to check the value of an environment variable, use the -p
flag
1$ dotenv -p NODE_ENV
If you want to pass flags to the inner command use --
after all the flags to dotenv-cli
.
E.g. the following command without dotenv-cli:
1mvn exec:java -Dexec.args="-g -f"
will become the following command with dotenv-cli:
1$ dotenv -- mvn exec:java -Dexec.args="-g -f"
or in case the env file is at .my-env
1$ dotenv -e .my-env -- mvn exec:java -Dexec.args="-g -f"
We support expanding env variables inside .env files (See dotenv-expand npm package for more information)
For example:
IP=127.0.0.1
PORT=1234
APP_URL=http://${IP}:${PORT}
Using the above example .env
file, process.env.APP_URL
would be http://127.0.0.1:1234
.
If your .env
variables include values that should not be expanded (e.g. PASSWORD="pas$word"
), you can pass flag --no-expand
to dotenv-cli
to disable variable expansion.
For example:
1dotenv --no-expand <command>
If your .env
file looks like:
SAY_HI=hello!
you might expect dotenv echo "$SAY_HI"
to display hello!
. In fact, this is not what happens: your shell will first interpret your command before passing it to dotenv-cli
, so if SAY_HI
envvar is set to ""
, the command will be expanded into dotenv echo
: that's why dotenv-cli
cannot make the expansion you expect.
One possible way to get the desired result is:
$ dotenv -- bash -c 'echo "$SAY_HI"'
In bash, everything between '
is not interpreted but passed as is. Since $SAY_HI
is inside ''
brackets, it's passed as a string literal.
Therefore, dotenv-cli
will start a child process bash -c 'echo "$SAY_HI"'
with the env variable SAY_HI
set correctly which means bash will run echo "$SAY_HI"
in the right environment which will print correctly hello
Another solution is simply to encapsulate your script in another subscript.
Example here with npm scripts in a package.json
1{ 2 "scripts": { 3 "_print-stuff": "echo $STUFF", 4 "print-stuff": "dotenv -- npm run _print-stuff", 5 } 6}
This example is used in a project setting (has a package.json). Should always install locally npm install -D dotenv-cli
You can add the --debug
flag to output the .env
files that would be processed and exit.
Override any environment variables that have already been set on your machine with values from your .env file.
1dotenv -e .env.test -o -- jest
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 15/30 approved changesets -- score normalized to 5
Reason
4 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 4
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More