node.js 如何将 npm 配置恢复/重置为默认值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20934343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 16:35:55  来源:igfitidea点击:

How to restore/reset npm configuration to default values?

node.jsnpm

提问by damphat

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

我已经打了npm set,并npm config set几次,现在我想恢复到默认值(一种恢复出厂设置的)。

Does npmprovide a command to do that? or Should I delete all configuration files by hands then reinstall it?

是否npm提供了执行此操作的命令?还是我应该手动删除所有配置文件然后重新安装它?

I need it both on linux Centosand on Windows 8.

我需要它都在linux CentosWindows 8

Thanks in advance!

提前致谢!

回答by Ilan Frumer

To reset user defaults

重置用户默认值

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

在命令行中运行它(或在 Windows 上运行git bash):

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 然后运行这个:

sudo sh -c 'echo "" > $(npm config get globalconfig)'

回答by robertklep

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.

如果您运行npm config edit,您将获得一个显示当前配置的编辑器,以及一个选项列表及其默认值。

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

但我认为没有“重置”命令。

回答by David Silva

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 rmis not mentioned in npm help config).

对于它的价值,您可以使用npm config delete <key>(或npm config rm <key>,但npm config rm中未提及的用法)将配置条目的值重置为默认值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

回答by jakub.g

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

如果它只是一个属性 - 假设您想临时更改一些默认值,例如禁用 CA 检查:您可以使用

npm config set ca ""

npm config set ca ""

To come back to the defaults for that setting, simply

要返回该设置的默认值,只需

npm config delete ca

npm config delete ca

To verify, use npm config get ca.

要验证,请使用npm config get ca.

回答by Surendra Parchuru

npm config edit

npm 配置编辑

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.

在编辑器中打开配置文件。使用 --global 标志编辑全局配置。现在您可以删除不需要的注册表并保存文件。

npm config listwill display the list of available now.

npm config list将显示现在可用的列表。

回答by MortenB

Config is written to .npmrcfiles 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 listwill allways list the active config.

配置已写入.npmrc文件,因此只需将其删除即可。NPM 按照这个顺序查找配置,下一个设置覆盖上一个。因此,请确保可能存在通常在每个项目中被覆盖的全局配置,这些配置在您删除每个项目的配置文件后变为活动状态。npm config list将始终列出活动配置。

  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)
  1. npm 内置配置文件 ( /path/to/npm/npmrc)
  2. 全局配置文件 ( $PREFIX/etc/npmrc)
  3. 每个用户的配置文件 ( $HOME/.npmrc)
  4. 每个项目的配置文件 ( /path/to/my/project/.npmrc)