How to restore/reset npm configuration to default values?

node.jsNpm

node.js Problem Overview


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.

node.js Solutions


Solution 1 - node.js

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)'

Solution 2 - node.js

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

Solution 3 - node.js

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.

Solution 4 - node.js

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.

Solution 5 - node.js

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.

Solution 6 - node.js

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)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondamphatView Question on Stackoverflow
Solution 1 - node.jsIlan FrumerView Answer on Stackoverflow
Solution 2 - node.jsDavid SilvaView Answer on Stackoverflow
Solution 3 - node.jsrobertklepView Answer on Stackoverflow
Solution 4 - node.jsjakub.gView Answer on Stackoverflow
Solution 5 - node.jsSurendra ParchuruView Answer on Stackoverflow
Solution 6 - node.jsMortenBView Answer on Stackoverflow