npm
- npm是一个共享代码的包管理器.
安装
npm install (with no args, in package dir)
npm install [<@scope>/]<name>
npm install [<@scope>/]<name>@<tag>
npm install [<@scope>/]<name>@<version>
npm install [<@scope>/]<name>@<version range>
npm install <alias>@npm:<name>
npm install <git-host>:<git-user>/<repo-name>
npm install <git repo url>
npm install <tarball file>
npm install <tarball url>
npm install <folder>
别名: npm i, npm add
common options: [-P|--save-prod|-D|--save-dev|-O|--save-optional|--save-peer] [-E|--save-exact] [-B|--save-bundle] [--no-save] [--dry-run]
卸载
npm uninstall [<@scope>/]<pkg>[@<version>]... [-S|--save|--no-save]
aliases: remove, rm, r, un, unlink
更新
-
npm update [-g] [<pkg>...] aliases: up, upgrade
-
npm outdated [[<@scope>/] …]
此命令会列出所有已经过时的包,可以及时进行包的更新
查看
npm ls [[<@scope>/]<pkg> ...]
aliases: list, la, ll
init
-
npm init [--yes|-y|--scope] npm init <@scope> (same as `npm exec <@scope>/create`) npm init [<@scope>/]<name> (same as `npm exec [<@scope>/]create-<name>`) npm init [-w <dir>] [args...]
- create a package.json file
help
npm help <term> [<terms..>]
Note: This command is unaware of workspaces.
root
npm root [-g]
config
npm config set <key>=<value> [<key>=<value> ...]
npm config get [<key> [<key> ...]]
npm config delete <key> [<key> ...]
npm config list [--json]
npm config edit
npm set <key>=<value> [<key>=<value> ...]
npm get [<key> [<key> ...]]
alias: c
Note: This command is unaware of workspaces.
- 代理npm config set proxy=http://xxx.com:8080
- 镜像npm config set registry=“http://r.cnpmjs.org”
- 安装淘宝镜像 npm install -g cnpm --registry=https://registry.npm.taobao.org
cache
npm cache add <tarball file>...
npm cache add <folder>...
npm cache add <tarball url>...
npm cache add <name>@<version>...
npm cache clean
aliases: npm cache clear, npm cache rm
npm cache verify
Note: This command is unaware of workspaces.
start
-
npm start [-- <args>]
- Description
This runs a predefined command specified in the “start” property of
a package’s “scripts” object.
If the “scripts” object does not define a “start” property, npm will run
node server.js.
Note that this is different from the default node behavior of runnin the
file specified in a package’s “main” attribute when evoking with node .
stop
-
npm stop [-- <args>]
- This runs a predefined command specified in the “stop” property of a package’s “scripts” object.
Unlike with npm help start, there is no default script that will run if the “stop” property is not defined.- Example
{
“scripts”: {
“stop”: “node bar.js”
}
}
- Example
restart
npm restart [-- <args>]
This restarts a project. It is equivalent to running npm run-script
restart.
If the current project has a "restart" script specified in package.json,
then the following scripts will be run:
1. prerestart
2. restart
3. postrestart
If it does not have a "restart" script specified, but it does have stop
and/or start scripts, then the following scripts will be run:
1. prerestart
2. prestop
3. stop
4. poststop
5. prestart
6. start
7. poststart
8. postrestart
test
npm test [-- <args>]
aliases: t, tst
- This runs a predefined command specified in the “test” property of a pack‐
age’s “scripts” object. -
{ "scripts": { "test": "node test.js" } }
version
npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=<prerelease-id>] | from-git]
'npm [-v | --version]' to print npm version
'npm view <pkg> version' to view a package's published version
'npm ls' to inspect current package/dependency versions
view
adduser
package.json
其它
npm-check
- -y/u(有否交互)-g(全局)
nrm
- 查看下载镜像源nrm ls
- 切换镜像源nrm use []
n
n stable