更新node
- 清除node缓存: sudo npm cache clean -f
- 安装node版本管理工具: sudo npm install n -g
- 使用版本管理工具安装最新node或指定node版本: sudo n stable 或 sudo n 8.9.4
npm access: 设置已发布的包的访问级别
npm access public [<package>]
npm access restricted [<package>]
npm access grant <read-only|read-write> <scope:team> [<package>]
npm access revoke <scope:team> [<package>]
npm access ls-packages [<user>|<scope>|<scope:team>]
npm access ls-collaborators [<package> [<user>]]
npm access edit [<package>]
public/restricted: 公开/受限
grant/revoke: 添加或删除用户或team对于包的只读/读写权限
ls-packages: 显示用户或team能访问的所有的包,并且还有访问级别。除了只读的公共包
ls-collaborators: 显示包的所有访问权限。将显示您至少有只读权限的包。如果user被传,则只针对用户所属team进行筛选
使用$EDITOR来设置访问权限
npm adduser: 注册npm用户
npm adduser [–registry=url] [–scope=@orgname] [–always-auth]npm-bin: 打印出在当前文件夹下,npm将会在哪里安装可执行文件
npm bin [-g|–global]npm bugs: 将会用浏览器打开package.json中配置的bugs.url参数,没有则打开包在npm官网上的url路径
npm bugs [<pkgname>]npm build: 相当于npm link和npm install的合集
npm build [<package-folder>]npm cache: 添加、列举、清除npm缓存文件夹
npm cache add <tarball file>
npm cache add <folder>
npm cache add <tarball url>
npm cache add <name>@<version>
npm cache ls [<path>]
npm cache clean [<path>]
- add: 添加包到本地缓存。主要是内部用。| 添加npm缓存文件夹
- ls: 显示缓存中的数据
- clean: 删除缓存文件夹中的数据
- npm completion: npm tab命令补全
npm config: 管理npm配置文件
npm config set <key> <value> [-g|–global]
npm config get <key>
npm config delete <key>
npm config list
npm config edit
npm get <key>
npm set <key> <value> [-g|–global]
npm config delete key
npm config editnpm dedupe: 删除重复包。搜索本地包树,并试图通过移动依赖关系进一步简化整体结果,使它们可以更有效地共享多个依赖包。
执行前:
a
+– b <– depends on c@1.0.x
|-- c@1.0.3
– d <– depends on c@~1.0.9
`– c@1.0.10执行后:
a
+– b
+– d
`– c@1.0.10npm deprecate: 更新包npm注册表,对于试图安装它提供一个警告。
npm deprecate <pkg>[@<version>] <message>npm dist-tag: npm标记
npm dist-tag add <pkg>@<version> [<tag>]
npm dist-tag rm <pkg <tag>
npm dist-tag ls [<pkg>]使用
npm install <name>@<tag>
npm install –tag <tag>npm docs: 用浏览器打开npm docs
npm docs [<pkgname> [<pkgname> …]]
npm docs .
npm home [<pkgname> [<pkgname> …]]
npm home .npm edit: 编辑已安装包
npm edit <pkg>[@<version>]npm explore 浏览已安装包
npm explore <pkg> [ – <cmd>]npm help: npm help <term> [<terms..>]
npm help access (浏览器打开npm access命令的使用)
npm help-search: 搜索npm markdown文档文件对于给定的标签,然后按照相关性排序列举出来
npm help-search <text>npm help-search access 结果如下:
npm help access access:24
npm help orgs access:21
npm help config access:9
npm help scope access:8
npm help publish access:3
npm help owner access:3
npm help version access:2
npm help package.json access:2
npm help team access:2
npm help index access:2
npm help coding-style access:1npm init: 初始化一个package.json文档
npm init [-f|–force|-y|–yes]运行npm init会在命令行中一一询问,然后让你对配置项输入值。如果加了-f|–force|-y|–yes,则会直接创建一个package.json, 不会再一一询问
npm install: 安装包。熟悉的不能再熟悉了
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 <tarball file> 安装一个.tgz文件
npm install <tarball url>
npm install <folder>
别名: npm i
common options: [-S|–save|-D|–save-dev|-O|–save-optional] [-E|–save-exact] [–dry-run]- -g|–global 安装到全局
- -S|–save 包添加到配置dependencies
- -D|–save-dev: 包添加到配置devDependencies
- -O|–save-optional: 包添加到配置optionalDependencies
- -E|-save-exact: 包添加到配置dependencies,但是版本号是一个确切的,而不是默认用^指定的一个版本范围
- -f|–force: 强制npm拉取包远程最新资源,及时包已经在本地存在
- –global-style
- –legacy-bundling:
- –link: 把安装到本地的包link到全局
- –no-bin-links: 阻止npm对任何可能包含的二进制包创建符号链接symlinks
- –no-optional: 阻止optionalDependencies依赖被安装
- –no-shrinkwrap: 忽略任何一个压缩(shrinkwrap)文件,并且使用package.json代替
- –nodedir=/path/to/node/source: 允许npm去寻找node源码以便npm可以编译原生模块
- –only={prod[uction]|dev[elopment]}: 只有non-devDependencies或devDependencies的被安装
- –tag=指定一个tag
- –dry-run: 报告会安装说明但没有安装任何实际的东西
npm install-test: 允许npm install后紧接允许npm test
npm install-test (with no args, in package dir)
npm install-test [<@scope>/]<name>
npm install-test [<@scope>/]<name>@<tag>
npm install-test [<@scope>/]<name>@<version>
npm install-test [<@scope>/]<name>@<version range>
npm install-test <tarball file>
npm install-test <tarball url>
npm install-test <folder>
别名: npm it
common options: [–save|–save-dev|–save-optional] [–save-exact] [–dry-run]
– npm link: 为npm包创建链接。分两步:
npm link (in package dir)
npm link [<@scope>/]<pkg>[@<version>]
别名: npm ln
- 在包目录下运行npm link,在全局创建了一个符号链接prefix/package-name指向当前包。
- 在其他目录下,运行npm link package-name将会创建一个符号链接从本地node_modules到第一步创建的全局的符号链接
注意:package-name是package.json中指定的
我在mac下设置link,其他目录引用package-name时老是报错。解决方法是:先npm install package-name, 然后npm link package-name
npm logout: 退登录npm registry
npm logout [–registry=<url>] [–scope=<@scope>]npm ls: 列出已安装的包,包括它们的依赖
npm ls [[<@scope>/]<pkg> …]
别名: list, la, llnpm指令格式: npm command [args]
npm outdated: 列出当前已经不是最新版本的包
npm outdated [[<@scope>/]<pkg> …]npm owner: 管理(添加、删除、列出)包所属的用户(列表)
npm owner add <user> [<@scope>/]<pkg>
npm owner rm <user> [<@scope>/]<pkg>
npm owner ls [<@scope>/]<pkg>npm pack: 针对包创建一个压缩包(tarball)
npm pack [[<@scope>/]<pkg>…]npm ping: ping npm registry配置和用户验证
npm ping [–registry <registry>]npm prefix: 打印本地或全局的prefix(本地:包含package.json的距离最近的父级路径)
npm prefix [-g]npm prune: 删除多余的包(不包括父包的依赖)
npm prune [[<@scope>/]<pkg>…] [–production]如果指定了–production 或NODE_ENV环境变量被设置为production,则此命令将移除devDependencies指定的包
npm publish: 发布npm包
npm publish [<tarball>|<folder>] [–tag <tag>] [–access <public|restricted>]
Publishes ‘.’ if no argument supplied
Sets tag ‘latest’ if no –tag specifiednpm rebuild: rebuild a package
npm rebuild [[<@scope>/<name>]…]
别名: npm rb
这个命令是在运行了npm build后的文件夹运行,当你安装了一个新的node版本,则必须重新编译所有的C++插件与新的二进制npm repo: 在浏览器中打开包仓库页repository
npm repo [<pkg>]npm restart
npm restart [– <args>]按顺序运行包的如下命令:
prerestart
prestop
stop
poststop
restart
prestart
start
poststart
postrestartnpm root: 打印npm包存储目录(<prefix>/node_modules)
npm root [-g]npm run-scripts: 运行package.json中配置的scripts命令
npm run-script <command> [– <args>…]
别名: npm runnpm search: 搜索包
npm search [-l|–long] [search terms …]
别名: s, senpm shrinkwrap: 锁定依赖版本。
运行后增加了npm-shrinkwrap.json,依赖包的版本号将锁定到固定版本npm star: “Starring”意味着你对这个包感兴趣
npm star [<pkg>…]
npm unstar [<pkg>…]npm stars: 列举出用户指定了star的包列表
npm stars [<user>]npm start: 运行package.json scripts配置的start命令
npm start [– <args>]npm stop: 运行package.json scripts配置的stop命令
npm stop[– <args>]npm tag: 标记一个已经发布的版本
npm tag <name>@<version> [<tag>]
详情参见dist-tagnpm team: 管理一个团队team
npm team create <scope:team>
npm team destroy <scope:team>
npm team add <scope:team> <user>
npm team rm <scope:team> <user>
npm team ls <scope>|<scope:team>
npm team edit <scope:team>npm test: 运行package.json scripts配置的test命令
npm test [– <args>]
npm tst [– <args>]npm uninstall: 卸载包
npm uninstall [<@scope>/]<pkg>[@<version>]… [-S|–save|-D|–save-dev|-O|–save-optional]
别名: remove, rm, r, un, unlinknpm unpublish: 从registry移除一个包
npm unpublish [<@scope>/]<pkg>[@<version>]npm update: 更新包
npm update [-g] [<pkg>…]npm version: bump一个包版本
npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease | 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
运行后
{ ‘zmrdlb-npm-module-test’: ‘1.0.1’,
npm: ‘3.10.9’,
ares: ‘1.10.1-DEV’,
http_parser: ‘2.7.0’,
icu: ‘57.1’,
modules: ‘48’,
node: ‘6.2.0’,
openssl: ‘1.0.2h’,
uv: ‘1.9.1’,
v8: ‘5.0.71.47’,
zlib: ‘1.2.8’ }
npm view: View registry info
npm view [<@scope>/]<name>[@<version>] [<field>[.<subfield>]…]
别名: info, show, vnpm whoami: 显示当前登录npm的用户信息
运行后: zmrdlb