129

I have played with npm set and npm config set for several times, now I want to reset to default values (a kind of factory reset).

Does npm provide a command to do that? Or should I delete all configuration files by hands then reinstall it?

I need to do it both on Linux CentOS and on Windows 8.

7 Answers 7

173

To reset user defaults

Run this in the command line (or git bash on windows):

echo "" > $(npm config get userconfig)
npm config edit

To reset global defaults

echo "" > $(npm config get globalconfig)
npm config --global edit

If you need sudo then run this instead:

sudo sh -c 'echo "" > $(npm config get globalconfig)'
4
  • If you need more information on how npm resolves configuration then look over here: npmjs.org/doc/config.html Commented Jan 5, 2014 at 14:35
  • worked great thanks. i destroyed my settings by installing sinopa :( Commented Mar 16, 2016 at 15:22
  • 1
    Think current link to npm config documentation is docs.npmjs.com/cli/config
    – rhand
    Commented Aug 25, 2020 at 1:53
  • 1
    What does npm config edit accomplish here? Doesn't that just open Vim? Commented Mar 15, 2022 at 20:16
78

For what it's worth, you can reset to default the value of a config entry with npm config delete <key> (or npm config rm <key>, but the usage of npm config rm is not mentioned in npm help config).

Example:

# set registry value
npm config set registry "https://skimdb.npmjs.com/registry"
# revert change back to default
npm config delete registry
5
  • 2
    this was a big help
    – suku
    Commented Jan 6, 2019 at 2:56
  • This wrecked my application. Now I get an error: Cannot find module 'config-chain' Commented Jan 24, 2019 at 12:13
  • Removing the node_modules folder fixed the config chain error. Commented Jan 24, 2019 at 12:24
  • Clearly what I was looking for after npm tries to pull from a private registry by default! Big thanks
    – Manu
    Commented Feb 15, 2019 at 9:59
  • I was dwelling in my tears for a couple of hours now, thank you! I changed the default path of npm because of a permission error and everything stopped working. Commented Mar 29, 2021 at 7:45
43

If you run npm config edit, you'll get an editor showing the current configuration, and also a list of options and their default values.

But I don't think there's a 'reset' command.

1
  • I have removed only the adress, saved and closed the file. Then I have reopend the file, and the complete line registry= was deleted
    – peter70
    Commented Mar 16, 2017 at 15:29
15

If it's about just one property - let's say you want to temporarily change some default, for instance disable CA checking: you can do it with

npm config set ca ""

To come back to the defaults for that setting, simply

npm config delete ca

To verify, use npm config get ca.

1
  • In my case: npm config -g rm <key> "-g is for global" Commented Jul 22, 2019 at 22:31
7

Config is written to .npmrc files so just delete it. NPM looks up config in this order, setting in the next overwrites the previous one. So make sure there might be global config that usually is overwritten in per-project that becomes active after you have deleted the per-project config file. npm config list will allways list the active config.

  1. npm builtin config file (/path/to/npm/npmrc)
  2. global config file ($PREFIX/etc/npmrc)
  3. per-user config file ($HOME/.npmrc)
  4. per-project config file (/path/to/my/project/.npmrc)
6

npm config edit

Opens the config file in an editor. Use the --global flag to edit the global config. now you can delete what ever the registry's you don't want and save file.

npm config list will display the list of available now.

0

Reinstalling nvm worked for me

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