npm install -save and npm install -save-dev looking to you

In fact, for many students just started node, for npm install -save and npm install -save-dev or points is not very clear, today's article, we take a good clear understanding of the difference between the two;

npm install moduleName # 安装模块到项目目录下

npm  install  -g moduleName  # -g 的意思是将模块安装到全局,具体安装到磁盘哪个位置,要看 npm config prefix 的位置。
npm  install  -save moduleName  # -save 的意思是将模块安装到项目目录下,并在package文件的dependencies节点写入依赖。
npm  install  -save-dev moduleName  # -save-dev 的意思是将模块安装到项目目录下,并在package文件的devDependencies节点写入依赖。
 
So the question is, should we use in the project in which four commands it? This is necessary, as the case may be. The following comparison of these four commands, after reading so you will no longer ask.
 

npm install moduleName 命令

1. Install the module to the project node_modules directory.
2. The module dependency does not write or dependencies devDependencies node.
3. When the download module will not run npm install initialize the project.

npm install -g moduleName 命令

1. Install the module to the global, module packages are not saved in the project node_modules directory.
2. The module dependency does not write or dependencies devDependencies node.
3. When the download module will not run npm install initialize the project.

npm install -save moduleName 命令

1. Install the module to the project node_modules directory.
2. The module dependency will write dependencies node.
3. Run npm install initialize the project, the module will be downloaded to the project directory.
4. Run npm install --production NODE_ENV variables specified value or production, will be automatically downloaded to the module node_modules directory.

npm install -save-dev moduleName 命令

1. Install the module to the project node_modules directory.
2. The module dependency will write devDependencies node.
3. Run npm install initialize the project, the module will be downloaded to the project directory.
4. Run npm install --production NODE_ENV variables specified value or production, does not automatically download module to node_modules directory.

to sum up

Module under devDependencies node is we need to use in the development, such as used in the project gulp, compress css, js modules. These modules in our project after deployment is not needed, so we can use the form -save-dev installed. Like express these modules are necessary to run the project, should be installed in the dependencies node, so we should use -save the form of installation.

Guess you like

Origin www.cnblogs.com/botugu/p/12042124.html