Registry / devops / dotnpmrc

dotnpmrc

JSON →
library0.1.3jsnpmunverified

A utility for programmatically generating .npmrc files for npm registry configuration. Version 0.1.3 is the latest stable release with TypeScript type definitions. It supports formatting with npm9 style, allows configuring scoped registries, authentication tokens, and root registry settings. Key differentiator: generates .npmrc content from a JavaScript/TypeScript object, enabling deterministic configuration in CI/CD pipelines and avoiding manual editing of .npmrc files. The library has a simple API with a single formatNpmrc function.

npm install dotnpmrc
INSTALL
IMPORT
SIG · DOTNPMRC
D
dotnpmrc
devopsjavascriptv0.1.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

formatNpmrc
import { formatNpmrc } from 'dotnpmrc'
const formatNpmrc = require('dotnpmrc')
ESM-only package; CommonJS require will not work.

Generates an .npmrc file with scoped registry and authentication token using the formatNpmrc function.

import { formatNpmrc } from 'dotnpmrc'; import fs from 'fs/promises'; const contents = formatNpmrc({ format: 'npm9', scopes: { example: { registry: 'https://npm-registry.example.com/', authToken: process.env.NPM_AUTH_TOKEN ?? '', alwaysAuth: true, }, }, root: { registry: 'https://registry.npmjs.org', }, }); await fs.writeFile('.npmrc', contents, { encoding: 'utf8' });
Debug
Known issues
gotchaThe default registry must be explicitly set in root.registry; otherwise, no default registry will be written.
fix
Always include root.registry to avoid an incomplete .npmrc that may fallback to npm's default registry.
affects: >=0.1.0
gotchaThe 'auth' field for scoped registries expects a base64-encoded string of 'username:password' but this is not validated; incorrect encoding will produce invalid .npmrc.
fix
Use authToken instead of auth when possible, or ensure the value is correctly base64-encoded with no extra whitespace.
affects: >=0.1.0
breakingThe output format is tied to npm9 format; future versions may change the format or support multiple versions, breaking assumptions about line endings and ordering.
fix
Pin to version 0.1.3 if the exact output format is critical.
affects: <=0.1.3
Errors
Common errors & fixes
TypeError: formatNpmrc is not a function
Using CommonJS require on an ESM-only package.
fix
Change to import { formatNpmrc } from 'dotnpmrc' and ensure the consuming module is also ES module.
SyntaxError: Unexpected token 'export'
The package is ES module but the project does not support ES modules (e.g., no 'type': 'module' in package.json or using older Node.js).
fix
Add "type": "module" to package.json or use dynamic import: const { formatNpmrc } = await import('dotnpmrc');
Upgrade
Version history
0.1.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
dotnpmrc — npm install dotnpmrc · libregistry