Last updated: Apr 20, 2023
Reading timeยท4 min
To reset your NPM configuration to the default values:
npm config get userconfig
command to get the location of your NPM
config file.Open your terminal and run the following command.
npm config get userconfig
The command prints the location of your config file.
Here is an example of running the command on Windows.
npm config get userconfig
To clear the contents of your config file and reset your NPM settings to the default, issue the following command.
echo "" > $(npm config get userconfig)
Here is an example of running the command on Windows.
If running the command in CMD on Windows fails, run the command in Git Bash.
You can use the npm config edit
file to verify that the configuration file has
been reset.
npm config edit
The npm config edit command opens the NPM config file in an editor.
If your NPM config file contains any information, it should be all comments.
Lines that start with a semicolon ;
are comments.
If you need to reset your global NPM configuration file to the default settings, issue the following command.
npm config get globalconfig
The command prints the path to your global NPM configuration file.
Here is an example of issuing the command on Windows.
Run the following command to reset your global NPM config to the default settings.
echo "" > $(npm config get globalconfig)
If running the command in CMD on Windows fails, run the command in Git Bash.
You can use the npm config --global edit
command to verify that your global
NPM file has been reset.
npm config --global edit
The command will open your global NPM configuration file in an editor.
The file will either be empty or will only contain comments.
Lines starting with a semicolon ;
are comments.
If the command fails with a permissions error, you might have to prefix it with
sudo
on macOS and Linux.
# if you get a permissions error sudo sh -c 'echo "" > $(npm config get globalconfig)'
If you get a permissions error on Windows, you have to open CMD or Git Bash as an administrator and rerun the command.
To open CMD as an administrator:
Click on the Search bar and type CMD.
Right-click on the Command Prompt application and click "Run as administrator".
echo "" > $(npm config get globalconfig)
If you need to reset a specific NPM configuration key to its default value, use
the npm config delete
command.
For example, if you want to reset the registry
key to its default value, you
would issue the following command.
npm config delete registry
Similarly, if you want to reset the https-proxy
key to its default value, you
would use the following command.
npm config delete https-proxy
The npm config delete command deletes the specified keys from all configuration files.
If you don't know the name of the key you want to reset, issue the
npm config edit
command.
npm config edit
The command will open your configuration file in an editor.
You can view the existing keys and delete the specific key you want to reset to the default.
If you also want to view your global settings, issue the command with the
--global
option.
npm config --global edit
Note that lines that start with a semicolon are comments and aren't read by NPM.
You can use the npm config list
command to print all your configuration
settings.
npm config list
You can use the -l
option if you also want to show the defaults.
npm config list -l
If you get an error while editing your NPM configuration files, try issuing the npm config fix command.
npm config fix
The command attempts to repair invalid configuration items.
If the error persists, you might have to delete your node_modules
directory
and reinstall your packages.
If you are on Windows, you can issue the following commands to reinstall your packages.
# for Windows rd /s /q "node_modules" del package-lock.json del -f yarn.lock # ๐๏ธ clean npm cache npm cache clean --force # ๐๏ธ install packages npm install
If you are on macOS or Windows, you can issue the following commands.
# for macOS or Linux rm -rf node_modules rm -f package-lock.json rm -f yarn.lock # ๐๏ธ clean npm cache npm cache clean --force # ๐๏ธ install packages npm install
Make sure to run the npm install
command after deleting your node_modules
.
I've also written a detailed guide on how to clear your proxy settings in NPM.
You can learn more about the related topics by checking out the following tutorials: