
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
dotenv-run-script
Advanced tools
Run NPM scripts with changing environments.
Install the package
npm install dotenv-run-script --save-dev
Add one or more scripts to your package.json
which uses one or more environment variables (GREETINGS
in the example below)
{
// ... other package stuff above
"scripts": {
"test": "echo $GREETING world!"
}
}
Create an .env
file with the variables used by the script
GREETING=Hello
npx dotenv-run-script test
Run the test
NPM script.
.env
filesThe dotenv-run-script
CLI takes any number of optional positional arguments, one for each .env
file to be loaded (in sequence).
The arguments are checked in sequence, all arguments will get parsed and expanded until either the argument --
or the argument does not resolve to a file.
The following loads a .env
followed by a .env.production
file and proceeds to execute the test
script.
npx dotenv-run-script .env .env.production -- test
It's recommended to add a script to the project's package.json to signal the use of dotenv-run-script
and ease the discovery of supported environments:
{
// ... other package stuff above
"scripts": {
"greet": "echo $GREETING $PLACE",
"production": "dotenv-run-script .env .env.production --",
"development": "dotenv-run-script .env .env.development --",
}
}
// .env
GREETING=Hello
PLACE=World!
// .env.production
PLACE=Universe!
// .env.development
PLACE=Localhost
In the example above, two environments are used .env.production
and .env.development
in addition to a shared .env
which includes common variables. Notice how the PLACE
variable gets overridden.
The greet
script can be invoked with
npm run production greet
See the simple and advanced examples for usage.
npm run
but any executableFAQs
Run NPM scripts in specific environments
The npm package dotenv-run-script receives a total of 3,972 weekly downloads. As such, dotenv-run-script popularity was classified as popular.
We found that dotenv-run-script demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.