简体   繁体   English

本地和全局节点 package 安装有什么区别?

[英]What is difference between local and global Node package installation?

I ask this question because I have been installing nodemon with npm and I see the results of installing through the suggested command at first sight, at the right side of the screen:我问这个问题是因为我一直在使用 npm 安装 nodemon,并且我在屏幕右侧看到了通过建议的命令安装的结果:

npm i nodemon

It is different from the installation instructions you can read above, on the Installation section.它与您可以在上面的安装部分阅读的安装说明不同。 There we see:在那里我们看到:

global installation:全局安装:

npm install -g nodemon

install nodemon as a local project dependency:将 nodemon 安装为本地项目依赖项:

npm install --save-dev nodemon

The thing is, what is difference between问题是,有什么区别

npm i nodemon

and

npm install -g nodemon

When I use the first command it tells me typical "nodemon is not recognized as internal or external command, operable program or batch file".当我使用第一个命令时,它告诉我典型的“nodemon 不被识别为内部或外部命令、可运行程序或批处理文件”。 To solve it I must install globally.为了解决它,我必须全局安装。

When you run npm i nodemon nodemon is installed as a local project dependency, to run nodemon on the CLI you would have to provide the pull path to it's installation, typically you would want to make this reference in your project's package.json file's scripts property, for instance: When you run npm i nodemon nodemon is installed as a local project dependency, to run nodemon on the CLI you would have to provide the pull path to it's installation, typically you would want to make this reference in your project's package.json file's scripts property , 例如:

{
    ...
    "scripts": { "nodemon": "nodemon index.js" },
    ...
}

This can then be executed by running npm run nodemon .这可以通过运行npm run nodemon来执行。

On the other hand running npm install -g nodemon or npm i -g nodemon installs nodemon on the global scope where it is referenced in your system PATH variable, that way you can easily call nodemon on the CLI and since it's full installation path is referenced in your system PATH variable it would execute like every other CLI command.另一方面,运行npm install -g nodemonnpm i -g nodemon将 nodemon 安装在全局 scope 上,因为您可以在系统中引用完整路径引用nodemon变量,因为它可以轻松调用它的完整路径在您的系统 PATH 变量中,它将像所有其他 CLI 命令一样执行。

Browser is made available to the current project (where it keeps all of the node modules in node modules) after local installation.本地安装后,浏览器可用于当前项目(它将所有节点模块保存在节点模块中)。 It will not be available as a command that the shell can resolve until you install it globally with npm install -g module , in which case npm will install it in a location where your path variable will resolve this command.在您使用npm install -g module全局安装它之前,它不会作为 shell 可以解析的命令使用,在这种情况下 npm 将在您的路径变量将安装它的位置安装它。 Typically, this is only good for using a module like so var module = require('module');通常,这仅适用于使用像这样的模块var module = require('module');

This documentation will help.文档将有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM