How to reset your NPM configuration to the default values

avatar
Borislav Hadzhiev

Last updated: Apr 20, 2023
4 min

banner

# Table of Contents

  1. How to reset your NPM configuration to the default values
  2. Resetting your Global NPM config file to the defaults
  3. Reset a specific NPM configuration key to its default value

# How to reset your NPM configuration to the default values

To reset your NPM configuration to the default values:

  1. Use the npm config get userconfig command to get the location of your NPM config file.
  2. Remove the contents of the file and save the changes.

Open your terminal and run the following command.

shell
npm config get userconfig

get location of npm config file

The command prints the location of your config file.

Here is an example of running the command on Windows.

cmd
npm config get userconfig

get config file path on windows

To clear the contents of your config file and reset your NPM settings to the default, issue the following command.

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

reset npm config to default settings

Here is an example of running the command on Windows.

reset npm config to default settings 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.

shell
npm config edit

The npm config edit command opens the NPM config file in an editor.

npm config edit

If your NPM config file contains any information, it should be all comments.

Lines that start with a semicolon ; are comments.

# Resetting your Global NPM config file to the defaults

If you need to reset your global NPM configuration file to the default settings, issue the following command.

shell
npm config get globalconfig

The command prints the path to your global NPM configuration file.

print path to global npm config file

Here is an example of issuing the command on Windows.

issue npm config get globalconfig command windows

Run the following command to reset your global NPM config to the default settings.

shell
echo "" > $(npm config get globalconfig)

reset global npm config to defaults

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.

shell
npm config --global edit

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.

shell
# 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:

  1. Click on the Search bar and type CMD.

  2. Right-click on the Command Prompt application and click "Run as administrator".

run cmd as administrator

  1. Rerun the command.
shell
echo "" > $(npm config get globalconfig)

reset global npm config as administrator windows

# Reset a specific NPM configuration key to its default value

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.

shell
npm config delete registry

Similarly, if you want to reset the https-proxy key to its default value, you would use the following command.

shell
npm config delete https-proxy

reset specific npm configuration key to default value

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.

shell
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.

shell
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.

shell
npm config list

You can use the -l option if you also want to show the defaults.

shell
npm config list -l

If you get an error while editing your NPM configuration files, try issuing the npm config fix command.

shell
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.

shell
# 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.

shell
# 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.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev