npm
install
moduleName :
安装模块到项目目录下
npm
install
moduleName -g:
-g 将模块安装到全局,具体安装到磁盘哪个位置,要看npm config prefix的位置。查看:npm config ls,修改:npm config set prefix.
-
npm
install
moduleName --save:(简写:-S)
-save 将模块安装到项目目录下,并在package文件的dependencies属性写入依赖。
npm
install
moduleName --
save-dev
:(简写:-D)-save-dev 将模块安装到项目目录下,并在package文件的devDependencies属性写入依赖。
npm install moduleName 命令
1. Install the module to the project node_modules directory.
2. not modify package.json file.
3. When the download module will not run npm install initialize the project.
npm install moduleName -g 命令
1. Install the module to the global, module packages are not saved in the project node_modules directory.
2. not modify package.json file.
3. When the download module will not run npm install initialize the project.
npm install moduleName --save 命令
1. Install the module to the project node_modules directory.
2. will be in package.json file dependencies property will depend on the module writes.
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 moduleName --save-dev 命令
1. Install the module to the project node_modules directory.
2. will be in package.json file devDependencies property will depend on the module writes.
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, it does not automatically download module to node_modules directory.
Third, the summary
Use principles: the need to use run-time packages use --save, otherwise the --save-dev.
Module under devDependencies attribute is that 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 dependencies attribute, so we should use -save the form of installation.