Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to override a local .npmrc when running `npm install`?

My project has an .npmrc located in its root, which contains the infamous ${NPM_TOKEN} hack and is required for CI, Staging, Production, etc.

In order to work around this reality, I'd like for developers to be able to tell npm to use an alternative .npmrc, which contains their _authToken, when installing dependencies. Something like, npm install . --npmrc=~/.npmrc. This would prevent them from having to pollute their system's environment variables, .bash_profile, etc.

Is this currently possible? (Doesn't seem so...) If not, are there any reasons why such an approach either wouldn't be possible (highly unlikely) or wouldn't be considered by the NPM team?

like image 304
pdoherty926 Avatar asked Sep 01 '16 02:09

pdoherty926


People also ask

Should Npmrc be ignored?

My answer would say it's best to ignore it and not push to repo. as if you have multiple Engineers contributing changes to a generated package for push to the registry each developer will have to have their own .

Does npm use Npmrc?

You can also install packages from feeds and public registries such as npmjs.com. To authenticate with Azure Artifacts, we must first set up our config file. Npm uses . npmrc configuration files to store feed URLs and credentials.

What is the location of .npmrc file?

npmrc file located in your user's home directory with the npm config command and the public URL of your repository group available in the repository list by clicking the copy button in the URL column of either Administration → Repository → Repositories or user's Browse page.

Why do we need .npmrc file?

npmrc file? This file is a configuration file for NPM, it defines the settings on how NPM should behave when running commands.


1 Answers

As luck would have it, this option already exists and can be used like so:

npm install . --userconfig=~/.npmrc
like image 177
pdoherty926 Avatar answered Oct 18 '22 17:10

pdoherty926