Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force NPM to use a locally hosted registry

When you install a node module, NPM gets the package from the default registry:

https://registry.npmjs.org

My company is hosting its own node registry and I want use it. How can I force NPM to use this local registry.

I don't want to use npm install --registry option.

Is there a way to make all the users on a specific machine to use this internal registry?

like image 592
OpenStack Avatar asked Jul 25 '16 18:07

OpenStack


2 Answers

What worked for me was, I ran following command :

npm config set registry PATH_TO_YOUR_LOCAL_REGISTRY

Another option is to create a .NPMRC file and put it into your project root directory. As mentioned in this link project specific npmrc file will take the highest priority & it will override other configuration. In this file just update the registry.

In npmrc file, add following:

registry = "https://path to local registry"
like image 96
OpenStack Avatar answered Oct 13 '22 18:10

OpenStack


You don't have to use the --registry option–you can just set the package.json to point to your internal repository [0]:

Set "private": true in your package.json to prevent your package from being published, and set:

"publishConfig": {
   "registry": "http://my-internal-registry.local"
}

to force it to be published only to your internal registry.

[0] https://docs.npmjs.com/misc/registry#i-dont-want-my-package-published-in-the-official-registry-its-private

like image 5
Kaushik Shankar Avatar answered Oct 13 '22 18:10

Kaushik Shankar