← All tools

npmrc-replace-env

Popularity 65 Updated Development & Build

A utility for generating .npmrc files based on configuration template and environment variables.

npmauto-collected

Installation

npm
npm install -g npmrc-replace-env

Install with npm.

npmrc-replace-env

A utility for dynamically generating .npmrc files based on configuration and environment variables.

Managing npm registry configurations and authentication tokens across different projects and environments can be cumbersome. This package aims to simplify this process by providing a utility that dynamically generates the .npmrc file based on a configuration file (.npmrc.config) and corresponding environment variables (.env).

This approach prioritizes security, preventing inadvertent exposure of sensitive information, like auth tokens in your .npmrc file, in version control systems.

Check out my article for a quick overview and insights about this utility here!

Table of Contents

  • Installation
  • Usage
  • Configuration
  • Define Environment Variables in .env
  • Command Line Options
  • Contributing
  • License

Installation

npm install npmrc-replace-env

yarn add npmrc-replace-env

pnpm add npmrc-replace-env

Note: While installing the package is an option, it's important to note that it's not required to use the utility. The utility can be invoked directly with npx without installing the package.

Usage

Run the utility using npx:

npx npmrc-replace-env

This will generate a .npmrc file (or override any existing .npmrc files) based on the configuration provided in a file named .npmrc.config.

Configuration

Create a file named .npmrc.config in the root of your project. This file should contain the configuration for your .npmrc file. The utility will replace placeholders in this configuration with corresponding environment variables.

Example .npmrc.config: