The `env-test` package is a small, specialized utility designed to set the `NODE_ENV` environment variable to `'test'` specifically when running Mocha tests. Its primary use case is through Mocha's `--require` flag, often configured in `mocha.opts`, to ensure that test environments consistently have `process.env.NODE_ENV = 'test'` without needing to add this line to every test file or rely on shell commands that might be skipped. Released as `1.0.0`, this package has seen no updates in over nine years, indicating it is an abandoned project. While it still functions for its narrow purpose, modern Node.js projects typically utilize more comprehensive environment management solutions like `dotenv`, `cross-env`, or `env-cmd` for loading `.env` files and conditionally setting environment variables across different platforms and contexts.
npm install env-testVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up `env-test` with Mocha using `mocha.opts` to automatically ensure `NODE_ENV` is set to 'test' for your test runs.
Migrate to `cross-env` for setting environment variables in `package.json` scripts (`cross-env NODE_ENV=test mocha`) or `dotenv` for loading `.env` files in your test setup if more complex environment management is needed.
For more flexible environment variable management (e.g., loading from `.env` files, setting multiple variables, or cross-platform compatibility), use packages like `dotenv` (programmatically) or `env-cmd` / `cross-env` (via npm scripts).
Ensure that `env-test` is the sole or primary source for setting `NODE_ENV` to 'test' in your testing workflow. Review your `package.json` scripts and other test setup files for conflicting environment variable assignments.
Ensure `env-test` is installed as a dev dependency: `npm install --save-dev env-test`.
Verify that your `mocha.opts` file is in the correct location (`test/mocha.opts` by default, or specified with `--opts <path>`). Double-check the `--require env-test` line for typos. Add `console.log(process.env.NODE_ENV);` to your test setup to debug when `NODE_ENV` is being set.
No dependency data recorded yet.