Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

switching npm registry based on directory

Tags:

I have recently started developing for node. The company that I work for has an internal npm registry. I want to know how to use different registry settings depending upon where I am developing. To illustrate, I have a directory structure like shown below:

~/Code | | -- My Projects | | | | -- Proj 1  | | -- Proj 2 | |-- My Company   |   |--Proj 1    |--Proj 2 

When I am developing in one of the projects in 'My Project', I would like the npm registry to point to https://registry.npmjs.org (the default registry). But when I am developing in one of the projects in 'My Company', I want npm registry to point to the company specific registry. Right now, my naive method is to use npm config set registry to update the registry.

like image 367
gprasant Avatar asked Sep 25 '13 13:09

gprasant


1 Answers

There are two distinct use cases for using your private npm registry:

  1. Installing: use the --reg or --registry flag:

    npm install mypackage --reg http://myreg.npmjitsu.com 
  2. Publishing: you can also use --reg or --registry, but I would highly recommend that you use the publishConfig setting in your package.json file (See: the npm documentation)

    {   "publishConfig": {     "registry": "http://myreg.npmjitsu.com"   } } 

    This prevents developers from accidentally publishing private modules to the public registry by forgetting the --registry flag

So add publishConfig to all of the package.json for your Company use --registry when installing from their private npm.

like image 185
indexzero Avatar answered Oct 10 '22 15:10

indexzero