Rohit Srivastava
Rohit Srivastava

Reputation: 1355

How can I add a .npmrc file?

I installed node on my Mac OS Sierra. I use Windows at my work so there I have a .npmrc file in the node folder but I don't seem to find that in mac. The problem is I want to add a registry of the format

    "scope=rohit-project@rohit-aquila:registry=https://registry.npmjs.org/
    //registry.npmjs.org/:_authToken=some-token"

How do I add it so that I can install the dependencies and modules for my project by running npm install on MAC OS Sierra.

I created a .npmrc file simply and added the above code...and therefater running npm install I get the following error

    rohitsrivastava$ npm install
    npm ERR! Darwin 16.4.0
    npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
    npm ERR! node v7.7.3
    npm ERR! npm  v4.1.2
    npm ERR! code E404

    npm ERR! 404 Not found : @rohit-project/notes
    npm ERR! 404 
    npm ERR! 404  '@rohit-project/notes' is not in the npm registry.
    npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
    npm ERR! 404 It was specified as a dependency of '@rohit-project/mega'
    npm ERR! 404 
    npm ERR! 404 Note that you can also install from a
    npm ERR! 404 tarball, folder, http url, or git url.

Upvotes: 132

Views: 641670

Answers (6)

oligofren
oligofren

Reputation: 22993

There are really two different questions here:

  1. Where is the .npmrc file created.
  2. How can you download private packages

Finding the location of your .npmrc file

Running npm config ls -l will show you all the implicit settings for npm, including what it thinks is the right place to put the .npmrc (the field userconfig), as this is environment/operating system dependant. But if you have never logged in (using npm login) it will be empty. Simply log in to create it.

To just output the path prop, issue npm config get userconfig.

Downloading private packages

You can actually do that by putting a .npmrc file in the NPM package's root. It will then be used by NPM when authenticating. It also supports variable interpolation from your shell so you could do stuff like this:

; Get the auth token to use for fetching private packages from our private scope
; see http://blog.npmjs.org/post/118393368555/deploying-with-npm-private-modules
; and also https://docs.npmjs.com/files/npmrc
//registry.npmjs.org/:_authToken=${NPM_TOKEN}

Pointers

Upvotes: 207

Prakash Ramasamy
Prakash Ramasamy

Reputation: 413

In case if you want to have .npmrc file at project level

  1. In the root directory of your project, create .npmrc file.
  2. In the .npmrc file, add key=value
  3. Save and close the file.

Upvotes: 1

Paul Ibeabuchi C.
Paul Ibeabuchi C.

Reputation: 27

In my case, updating my npm version helped me. So just to be sure, make sure your npm is up to date.

npm install -g npm@latest

Upvotes: 0

sunil
sunil

Reputation: 6614

In MacOS Catalina 10.15.5 the .npmrc file path can be found at

/Users/<user-name>/.npmrc

Open in it in (for first time users, create a new file) any editor and copy-paste your token. Save it.

You are ready to go.

Note: As mentioned by @oligofren, the command npm config ls -l will npm configurations. You will get the .npmrc file from config parameter userconfig

Upvotes: 31

Mayank
Mayank

Reputation: 342

Assuming you are using VSTS run vsts-npm-auth -config .npmrc to generate new .npmrc file with the auth token

Upvotes: 1

Rahul Hirve
Rahul Hirve

Reputation: 1139

This issue is because of you having some local or private packages. For accessing those packages you have to create .npmrc file for this issue. Just refer the following link for your solution. https://nodesource.com/blog/configuring-your-npmrc-for-an-optimal-node-js-environment

Upvotes: 2

Related Questions