npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dotenv-run-script

v0.4.1

Published

Run NPM scripts in specific environments

Downloads

23,116

Readme

dotenv-run-script

Run NPM scripts with changing environments.

Usage

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.

Using multiple .env files

The 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

Adding a script per environment

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

Examples

See the simple and advanced examples for usage.

Alternatives you might consider using

  • dotenv's preload script
  • dotenv-run which provide similar, but limited functionality to this package. At the time of writing this, it does not
    • use dotenv-expand to assign variables from other variables.
    • allow multiple .env files to be loaded in sequence
    • call npm run but any executable