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.
npm install node-env-runVerified import paths — ran on the pinned version, not inferred.
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.
To explicitly override existing variables, use the `--force` or `-f` flag: `nodenv --force .` This should be used cautiously, especially in shared environments.
Always add `.env` files to your `.gitignore` to prevent them from being committed. For team collaboration, use template files (e.g., `.env.example`) to document required variables.
Ensure the `--env` or `-E` flag points to the correct `.env` file path relative to where `nodenv` is executed. If no flag is provided, `nodenv` defaults to `./.env` in the current working directory.
Refer to the official `dotenv` and `node-env-run` GitHub repositories for specific changelog details when upgrading from older major versions. Test your scripts thoroughly after upgrading.
If installed locally (`--save-dev`), run it via `npm run <script-name>` (e.g., `npm run dev` if `dev: "nodenv ."` is in `package.json`). If desired globally, install with `npm install -g node-env-run`. Alternatively, use `npx node-env-run`.
Verify the `.env` file exists at the expected path (defaults to `./.env` or the path specified by `-E`). Ensure variables are defined in `KEY=VALUE` format. Check for typos in both the `.env` file and the code accessing `process.env.KEY`.
While often harmless, review your project's module setup, particularly `package.json`'s `type` field and how dependencies are loaded. This warning is often transient and not directly caused by `node-env-run` itself.