I have a few npm package listed in package.json file , some are public and some are private. I want to install both types of packages in single command by using npm install
.
If npm registry set on global, private package shows 404
, so how to achieve this by single command.I want Both types of package install on node_modules.
The faster solution is what @hugomarisco suggested in the comment section. I'll assume your private package is in any registry (A) and the remainings are fetched from npmjs (B).
To make it more clear, you can use verdaccio and set up your multiples registries as uplinks as is visualized here.
Your uplink configuration might look like this,
uplinks:
npmjsA:
url: https://registry.npmjs.org/
registryB:
url: http://mirror.local.net/
and then just define the package access to each remote by patterns
packages:
'my-private-*':
access: $authenticated
publish: $authenticated
proxy: registryB
'**':
access: all
publish: $authenticated
proxy: npmjs
In such way, you can access your private packages safely while verdaccio fetch for you those belong any public registry as npmjs.
In your terminal just do
npm set registry http://localhost:4873
npm install
and you are set. I hope that helps.
npm --usercofig=./.npmrccorp i
: This will install the modules as mentioned in package.json
while considering the configuration file supplied by the --userconfig
argument. The last i
and install
are interchangeable. This can be rewritten as npm --usercofig=./.npmrccorp
install also
To install both private and public packages with single npm --usercofig=./.npmrccorp i
command you need to maintain both the dependencies
in package.json
dependencies node and then there should be a .npmrccorp file containing your authentication token as follows:
package.json:
{
"dependencies": {
"@org/package1": "^1.0.14",
"@org/package2": "^1.0.0",
"public package1": "^1.5.0",
"public package1": "^2.117.0",
}
}
.npmrccorp
//registry.npmjs.org/:_authToken=a*******-****-****-****-***********1 (32 bit authentication token)
After did all experiment, i up all my private package to server as a scoped package. like as @private/jsonwrite
, @private
is my scoped name. then i write below config in .npmrc
@private:registry=https://npmjs.my-private-repo.net
then just run npm install
, it works both on remote and global package. Which is scoped package download from .npmrc
given link and rest of others from global npm.