1. What is NPM?
NPM is a JavaScript package management tool that installs Nodejs (what? You don't know node? , we will automatically install NPM when we total: https://nodejs.org/).
To view the installed NPM version, simply open the CMD console and enternpm -v
NPM makes it easy for JavaScript developers to share and reuse code, and it makes it easy for you to update the code you share.
NPM can upgrade itself by using the following commands:npm install npm -g
2. Use of NPM
In the following code example,:<> represents a required parameter, [] indicates an optional parameter
#最常用命令 2.1. Init: Used to initialize the project
/* * npm init [-f|--force|-y|--yes] *///在文件夹中打开cmd,然后输入npm init,打开项目初始化向导npm init //如果文件夹名称满足npm的module name,//那么使用如下方式,可以直接生成一个默认的package.json//如果文件夹名称不满足要求,那么会出错npm init -fnpm init --forcenpm init --force=true npm init -ynpm init --yesnpm init --yes=true
2.2, install: For the installation of modules
/* * NPM Install (with no args to a package dir) * NPM install <tarball file> * NPM Install <tarball url> * NP M Install <folder> * NPM install [@<scope>/]<name> [--save|--save-dev|--save-optional] [--save-exact ] * NPM Install [@<scope>/]<name>@<tag> * NPM Install [@<scope>/]<name>@<version> * NPM Install [@<scope>/]<name>@<version range> * NPM I (with any of the previous argument usage) *///Direct use NPM Install or npm I, means that depending on package.json, installing all dependent NPM INSTALLNPM i//If you add the--production parameter, then only the Dependencies module will be installed,// Instead of installing Devdependencies's internal module NPM install--PRODUCTIONNPM I--production//use the global context to initialize NPM install-gnpm i-g//Install the specified module NPM Install <PACKAGENAME>NPM installs <packageName> G//Global installation NPM installed <packageName>@<version>// Specify the module version to install NPM install <packageName>@<version_start-version_end>//Specify the module version to install NPM install <packagename >--registry=<url>//Warehouse address for designated snacks NPM install <packagename&Gt --msvs_version=<vs_version>//Specify the VS version used by the build NPM install <packageName>--save// Install the module and modify Package.json dependenciesnpm install <packageName>--save-dev// Install the module and modify the Package.json devdependenciesnpm install <tarball url>//From the specified compressed package address, as shown in the following example: NPM install https://github.com /INDEXZERO/FOREVER/TARBALL/V0.5.6NPM Install <tarball file>//From the specified compression package, as follows (note the package format): NPM Install del-1.2.0.tar.gz//using the. tgz and. tar.gz format NPM Install @<scope>/<packagename>//install private package
2.3. Uninstall: for unloading module
/* * npm uninstall [@<scope>/]<package> [--save|--save-dev|--save-optional] *///直接卸载模块,加上-g参数,表示卸载全局的模块npm uninstall <packageName> npm uninstall <packageName> -g//卸载时同时修改package.json文件npm uninstall <packageName> --save-devnpm uninstall <packageName> --save
2.4. UPDATE: for updating modules
/* * npm update [-g] [<name> [<name> ...]] *///更新一个或多个模块,加上-g参数,表示更新全局的模块npm update <packageName> [packageName2...]npm update <packageName> [packageName2...] -g//更新时同时修改package.json文件npm update <packageName> [packageName2...] --save-devnpm update <packageName> [packageName2...] --save
2.5. config: for setting NPM parameters
//设置指定参数npm config set <key> <value> [--global]npm set <key> <value> [--global] //可以省略config//获取现有参数值npm config get <key>npm get <key> //可以省略config//删除指定参数,此时参数值会变为默认值npm config delete <key>//查看npm信息;注意:此命令不是查看所有参数配置npm config list//编辑全量的npm配置文件(.npmrc)npm config edit//可以将config使用c代替,执行以上所有命令npm c [set|get|delete|list]
2.6. Cache: Management Pack caching
//将指定的包加入npm缓存npm cache add <tarball file>npm cache add <folder>npm cache add <tarball url>npm cache add <name>@<version>//查看现有的npm包缓存,如果加上path参数,则查看该路径下的文件npm cache ls [<path>] eg: npm cache ls gulp//清空缓存。如果加上path,则清理指定路径下的包缓存npm cache clean [<path>]eg: npm cache clean gulp
NPM usage details (UP)