@ethanresnick/node-env-run v3.0.3
node-env-run
Command-line tool to read
.envfiles and execute scripts/commands after loading those environment variables
- Uses dotenvunder the hood
- Easy to configure
- Flexible command to execute
- Let's you override existing environment variables
Installation
Install per project:
I recommend installing this module as a devDependency for the respective project.
Install via yarn:
yarn add node-env-run --devInstall via npm:
npm install node-env-run --save-devInstall globally:
You can alternatively install the module globally if you want to:
npm install node-env-run --globalUsage
Add a new scripts entry to your package.json. Example:
{
  "scripts": {
    "dev": "nodenv .",
    "test": "nodenv -E test/.env test/test.js"
  }
}Or use it with npx:
npx node-env-run .Documentation
This module uses under the hood the dotenv module to parse the .env file. For more information about how to structure your .env file, please refer to its documentation.
Usage examples:
Start up the main file in package.json with the enviornment variables from .env:
nodenv .Start Node.js REPL with set environment variables from .env.repl:
nodenv -E .env.replRun Python file with overridden environment variables:
nodenv app.py --exec python --forceRun server.js file using nodemon:
nodenv server.js --exec nodemonPass --inspect flag for debugging after --:
nodenv someScript -- --inspectArguments
You can pass node-env-run a variety of arguments. These are the currently supported arguments:
| Flag | Type | Description | 
|---|---|---|
| --encoding | string | Lets you specify the encoding of the .envfile. Defaults toutf8encoding. | 
| --envor-E | string | Specifies the path to the .envfile that should be read | 
| --execor-e | string | This lets you specify a command other than nodeto execute the script with. More in the next section. | 
| --forceor-f | boolean | Flag to temporarily override existing environment variables with the ones in the .envfile | 
| --help | boolean | Displays the usage/help instructions | 
| --verbose | boolean | Flag to enable more verbose logging | 
| --version | boolean | Displays the current version of the package | 
Using node-env-run with other executables
You can use node-env-run with other executables. This is particularly useful if you try to combine it with things like babel-node or ts-node:
nodenv index.ts --exec "ts-node"However, you can also use it with completely unrelated executables such as python:
nodenv app.py --exec pythonContributors
| Dominik Kundel💻 | 
|---|
License
MIT
7 years ago