npmrc-replace-env is a Node.js utility designed to simplify the management of npm registry configurations and authentication tokens across various projects and environments. It dynamically generates or updates a `.npmrc` file based on a user-defined `.npmrc.config` template and corresponding environment variables, which can be loaded from `.env` files. The current stable version is 1.2.1. The project follows a regular release cadence with frequent patch releases addressing bug fixes and dependency updates, alongside minor releases introducing new features like shell-style variable syntax support. Its primary differentiator is its focus on securely managing sensitive npm configuration details by preventing their exposure in version control, leveraging environment variables for token replacement. It supports both prefix-based (`NPMRC_TOKEN`) and shell-style (`$TOKEN`, `${TOKEN}`) placeholder syntax, offering flexibility for different CI/CD environments, including GitHub Actions. The tool is primarily used via its command-line interface with `npx` and requires Node.js version 24.0.0 or higher for current versions.
npm install npmrc-replace-envVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to set up a `.npmrc.config` and `.env` file, then use `npx npmrc-replace-env` to generate a `.npmrc` with environment variables replaced.
Upgrade to `npmrc-replace-env@1.2.1` or newer to ensure all URL path placeholders are correctly replaced.
Upgrade to `npmrc-replace-env@1.2.0` or newer to utilize shell-style placeholder syntax. For older versions, ensure placeholders use the `NPMRC_` prefix (or a custom prefix) and avoid shell syntax.
Upgrade your Node.js environment to version 24.0.0 or newer. Check the package's `engines` field in `package.json` for the exact requirement.
Add `.npmrc` to your project's `.gitignore` file. Never commit `.npmrc` files containing sensitive information.
Ensure your environment variables are named with the `NPMRC_` prefix (e.g., `NPMRC_MY_TOKEN`) or utilize the `--prefix <YOUR_PREFIX>` or `--no-prefix` command-line options when running the utility.
Upgrade your Node.js installation to version 24.0.0 or newer.
Upgrade to `npmrc-replace-env@1.2.1` or newer to fix the regex for URL path placeholders.
Upgrade to `npmrc-replace-env@1.2.0` or newer. Alternatively, use the `NPMRC_MY_TOKEN` prefix-based syntax for older versions.
Rename your environment variable to `NPMRC_MY_APP_TOKEN` in both `.env` and `.npmrc.config`, or use the `--prefix <YOUR_PREFIX>` or `--no-prefix` command-line options to customize recognition.
Ensure that a file named `.npmrc.config` exists in the root of your project or the directory from which you are running `npx npmrc-replace-env`.