284

I create a.bat on windows 7, the content of a.bat is:

@echo off
npm config set registry https://registry.npmjs.org/

and then run a.bat, but not working, I find the word "set" is special keyword for npm and bat, is there any methods to resolve this question?

7
  • 431
    Does anyone else just come to this post every time they want to see what the npm registry url is? haha Jul 10, 2016 at 8:21
  • 12
    FYI: I needed the .com version of the registry: i.e. https://registry.npmjs.com/ rather than https://registry.npmjs.org/
    – infl3x
    Sep 21, 2016 at 1:48
  • 9
    @kevingilbert100 npm config get registry to know the registry URL
    – Sridhar
    Dec 31, 2018 at 4:39
  • 4
    @Sridhar Nope. That only provides the current set registry, not the "official" npm registry.
    – Emobe
    Jan 30, 2020 at 9:46
  • 1
    Had to change from https to http May 27, 2020 at 6:05

10 Answers 10

291

You shouldn't change the npm registry using .bat files. Instead try to use modify the .npmrc file which is the configuration for npm. The correct command for changing registry is

npm config set registry <registry url>

you can find more information with npm help config command, also check for privileges when and if you are running .bat files this way.

4
  • may be the method I used is not suitable for my question, but still thanks for your answer:)
    – mopduan
    Mar 16, 2014 at 4:21
  • 3
    @MarcellodeSales try npm config set registry=<registry url>
    – L1fescape
    Aug 22, 2014 at 18:30
  • 13
    The config part is not necessary, can run just npm get registry to see your current, and npm set registry https://registry.npmjs.org/ to set it back to the default.
    – Alec Rust
    Aug 2, 2017 at 10:28
  • is npm config set registry <local node_modules folder> possible. If i don't want to download anything from internet and all artifacts are within the app. Sep 7, 2018 at 11:22
138

We can also run npm install with registry options for multiple custom registry URLs.

npm install --registry=https://registry.npmjs.org/ 
npm install --registry=https://custom.npm.registry.com/ 
1
  • 3
    running npm install while .npmrc is set for a private artifactory was causing a lot of pains. This has saved me a couple of hours 🙌🏼
    – Mahmut C
    Jul 20, 2020 at 16:00
63

You can change using the .bat make sure you run the call command prior, hopefully this helps anyone in future making similar .bat commands

call npm config set registry https://registry.npmjs.org/
0
36

On version 4.4.1, you can use:

npm config set @myco:registry=http://reg.example.com

Where @myco is your package scope. You can install package in this way:

npm install @myco/my-package

ref: https://docs.npmjs.com/misc/scope

33
  1. Set npm registry globally

    use the below command to modify the .npmrc config file for the logged in user

    npm config set registry <registry url>

    Example: npm config set registry https://registry.npmjs.org/


  1. Set npm registry Scope

    Scopes allow grouping of related packages together. Scoped packages will be installed in a sub-folder under node_modules folder.

    Example: node_modules/@my-org/packagaename

    To set the scope registry use: npm config set @my-org:registry http://example.reg-org.com

    To install packages using scope use: npm install @my-org/mypackage

    whenever you install any packages from scope @my-org npm will search in the registry setting linked to scope @my-org for the registry url.


  1. Set npm registry locally for a project

    To modify the npm registry only for the current project. create a file inside the root folder of the project as .npmrc

    Add the below contents in the file

   registry = 'https://registry.npmjs.org/'
1
  • 3
    Thank you! I've tried to npm config set registry https://..., but when I've doing npm config get registry it was returning http://..., and problem was that someone commited .nmprc with http://... and it takes precedence over global config. I spend like good 10 minutes until I understand what happens with help of your post :)
    – Ruslan
    Sep 29, 2021 at 12:46
21

Probably I am too late to answer. But if anybody need it, following works fine, as I have used it a lot of times.

npm config set registry=https://registry.npmjs.com/
5

On npm version 3.7.3

npm set registry=http://whatever/

1

By executing your .bat you are setting config for only that session not globally. When you open and another cmd prompt and run npm install that config will not set for this session so modify your .bat file as

@echo off
npm config set registry https://registry.npmjs.org/
@cmd.exe /K
0
2.name can no longer contain capital letters

don't use capital letters for your package:

npm install --save uex

use this:

npm install --save vuex
0

You might not be able to change npm registry using .bat file as Gntem pointed out. But I understand that you need the ability to automate changing registries. You can do so by having your .npmrc configs in separate files (say npmrc_jfrog & npmrc_default) and have your .bat files do the copying task.

For example (in Windows): Your default_registry.bat will have

xcopy /y npmrc_default .npmrc

and your jfrog_registry.bat will have

xcopy /y npmrc_jfrog .npmrc

Note: /y suppresses prompting to confirm that you want to overwrite an existing destination file.

This will make sure that all the config properties (registry, proxy, apiKeys, etc.) get copied over to .npmrc.

You can read more about xcopy here.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.