Node Environment Run

4.0.2 · active · verified Tue Apr 21

node-env-run is a command-line utility designed to simplify the process of loading environment variables from `.env` files and executing Node.js scripts or other commands with those variables pre-loaded. It leverages the popular `dotenv` library under the hood for parsing `.env` files. The package is currently at version 4.0.2 and appears to be actively maintained; while an explicit release cadence isn't stated in the provided documentation, updates often follow the underlying `dotenv` library or address bug fixes. Its key differentiators include flexible command execution (e.g., with `nodemon`, `python`), the ability to specify custom `.env` file paths, and options to override existing environment variables, making it a robust tool for local development setups.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to set up `node-env-run` in `package.json` to load environment variables from a `.env` file and execute the main script, showing variables being accessed.

// package.json
{
  "name": "my-app",
  "version": "1.0.0",
  "scripts": {
    "start": "nodenv ."
  }
}

// .env
HELLO_MESSAGE="Hello from .env!"
PORT=3000

// index.js (main script)
console.log(`Loading application on port ${process.env.PORT ?? 'unknown'}.`);
console.log(process.env.HELLO_MESSAGE ?? 'No message loaded.');

// To run:
// 1. npm install node-env-run --save-dev
// 2. npm run start

view raw JSON →