50

I want to be able to clone a git repository using a URL as specified here

<protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit-ish>]

I am getting an error saying

npm ERR! 404 Registry returned 404 for GET on https://registry.npmjs.org/XYZ

So I should also be able to specify the registry while doing since modules are supposed to be picked up from a internal repository.

Is it possible to specify registry while doing npm install with git remote url?

Mike Morearty
  • 9,953
  • 5
  • 31
  • 35
gurvinder372
  • 66,980
  • 10
  • 72
  • 94

3 Answers3

105

npm gets its config settings from the command line, environment variables, and npmrc files. You can try to specify registry in a npmrc file, and module in the command line. To change registry, you can use command:

npm config set registry <registry url>

You can also change configs with the help of -- argument. Putting --foo bar on the command line sets the foo configuration parameter to "bar". So you can try something like that:

 npm install http://git.repo.url --registry=https://your.registry.local/
Ashish Modi
  • 7,529
  • 2
  • 20
  • 35
Alexandr Lazarev
  • 12,554
  • 4
  • 38
  • 47
  • 1
    Thanks, but I have already tried it. It doesn't work. Is there also a way of bypassing proxy in the same command? – gurvinder372 Feb 25 '16 at 10:37
  • What do you mean by "doesn't work"? Try to call `npm config ls -l ` before running `npm install` with `--registry` argument, and seek `; userconfig /Users/username/.npmrc` line. Next line should be the registry option itself: `registry = "http://my-internal-registry.local/"`. Afterwards, call the command to install and change registry, and look to the configs once again. Registry option should be changed. – Alexandr Lazarev Feb 25 '16 at 11:34
  • To bypass proxy, you should change `proxy` option in configs, and as I have already mentioned, you can do it with the help of `--` argument. It should look like: `npm intall module --proxy http://domain%5Cuser:pass@host:port` – Alexandr Lazarev Feb 25 '16 at 11:35
  • `What do you mean by "doesn't work"?` It is not even recognizing the registry command with or without proxy. It simply checks in the global repository. – gurvinder372 Feb 25 '16 at 11:43
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/104528/discussion-between-lazarev-alexandr-and-gurvinder372). – Alexandr Lazarev Feb 25 '16 at 11:44
  • 2
    This works but the syntax is actually: `--registry=https://your.registry.local/` You were missing the equals sign. – Matt Hughes Jul 15 '18 at 13:32
  • 3
    It seems that `npm install --registry http://customregistry.foo.bar.com` flag override does not seems to actually respect fully the registry address, but still tries connect to the npm default registry. Nor does the `--registry=http://customregistry.foo.bar.com` – Maksim Luzik Oct 29 '18 at 11:34
  • 3
    The `--registry` argument is actually not working at all, see [npm install](https://docs.npmjs.com/cli/install.html) or [yarn add](https://yarnpkg.com/lang/en/docs/cli/add/) documentation. – merlin.ye Dec 27 '19 at 13:06
8

Not the best way but If you are using mac or linux even in you can set alias for different registries.

##############NPM ALIASES######################
alias npm-default='npm config set registry https://registry.npmjs.org'
alias npm-sinopia='npm config set registry http://localhost:4873/'
owais
  • 4,752
  • 5
  • 31
  • 41
6

Yes, you need to use:

npm config set registry <registry url>.

to make sure you install your package from the registry inside your company.

If you are doing npm -i -g, this is to install globally.

you need to do:

npm -g config set registry <registry url>
Xiaoming Dou
  • 151
  • 2
  • 2
  • The above works with npm 6.x, for 8.x, it is npm config set = [= ...]; Refer: https://docs.npmjs.com/cli/v8/commands/npm-config – Ironluca Mar 08 '22 at 09:25