1 查看npm指令帮助
npm指令帮助
C:\Users\10321>npm -h
npm <command>
Usage:
npm install install all the dependencies in your project
npm install <foo> add the <foo> dependency to your project
npm test run this project's tests
npm run <foo> run the script named <foo>
npm <command> -h quick help on <command>
npm -l display usage info for all commands
npm help <term> search for help on <term> (in a browser)
npm help npm more involved overview (in a browser)
All commands:
access, adduser, audit, bin, bugs, cache, ci, completion,
config, dedupe, deprecate, diff, dist-tag, docs, doctor,
edit, exec, explain, explore, find-dupes, fund, get, help,
hook, init, install, install-ci-test, install-test, link,
ll, login, logout, ls, org, outdated, owner, pack, ping,
pkg, prefix, profile, prune, publish, rebuild, repo,
restart, root, run-script, search, set, set-script,
shrinkwrap, star, stars, start, stop, team, test, token,
uninstall, unpublish, unstar, update, version, view, whoami
Specify configs in the ini-formatted file:
C:\Users\10321\.npmrc
or on the command line via: npm <command> --key=value
More configuration info: npm help config
Configuration fields: npm help 7 config
npm@8.5.0 D:\Envs\nvm\nvm\v16.14.2\node_modules\npm
cnpm指令帮助
C:\Users\10321>cnpm -h
Usage: cnpm [options]
Options:
-h, --help output usage information
-v, --version show full versions
-r, --registry [registry] registry url, default is https://registry.npmmirror.com
-w, --registryweb [registryweb] web url, default is https://npmmirror.com
--disturl [disturl] dist url for node-gyp, default is https://npmmirror.com/mirrors/node
-c, --cache [cache] cache folder, default is C:\Users\10321\.cnpm
-u, --userconfig [userconfig] userconfig file, default is C:\Users\10321\.cnpmrc
-y, --yes yes all confirm
--ignore-custom-config ignore custom .cnpmrc
--proxy [proxy] set a http proxy, no default
Usage: cnpm [option] <command>
Help: http://cnpmjs.org/help/cnpm
Extend command
web open cnpm web (ex.: cnpm web)
check [ingoreupdate] check project dependencies, add ignoreupdate will not check modules' latest version(ex.: cnpm check, cnpm check -i)
doc [moduleName] open document page (ex.: cnpm doc egg)
sync [moduleName] sync module from source npm (ex.: cnpm sync egg)
user [username] open user profile page (ex.: cnpm user fengmk2)
npm command use --registry=https://registry.npmmirror.com
where <command> is one of:
add-user, adduser, apihelp, author, bin, bugs, c, cache,
completion, config, ddp, dedupe, deprecate, docs, edit,
explore, faq, find, find-dupes, get, help, help-search,
home, i, info, init, install, isntall, la, link, list, ll,
ln, login, ls, outdated, owner, pack, prefix, prune,
publish, r, rb, rebuild, remove, restart, rm, root,
run-script, s, se, search, set, show, shrinkwrap, star,
start, stop, submodule, tag, test, tst, un, uninstall,
unlink, unpublish, unstar, up, update, v, version, view,
whoami
npm <cmd> -h quick help on <cmd>
npm -l display full usage info
npm faq commonly asked questions
npm help <term> search for help on <term>
npm help npm involved overview
Specify configs in the ini-formatted file:
C:\Users\10321\.cnpmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config
2 常用指令
全局安装,node包会被下载到全局目录下
npm install xxx -g
本地安装,安装在当前文件夹下面
npm install xxx
运行依赖
npm install xxx -g --save
安装完成之后保存在package.json 的dependencies中
开发依赖
npm install xxx -g --save-dev
安装之后保存在package.json的devdependencies中
删除全局模块
npm uninstall -g <package>
删除局部模块
npm uninstall <package>
删除全局模块,同时清除package.json
npm uninstall 模块:删除模块,但不删除模块留在package.json中的对应信息
npm uninstall 模块 --save 删除模块,同时删除模块留在package.json中dependencies下的对应信息
npm uninstall 模块 --save-dev 删除模块,同时删除模块留在package.json中devDependencies下的对应信息
3 发布自己的node包
第一次发布
在终端输入npm adduser,提示输入账号,密码和邮箱,然后将提示创建成功
不是第一次发布
在终端输入npm login,然后输入你创建的账号和密码,和邮箱,登陆
【注意】npm adduser成功的时候默认你已经登陆了,所以不需要再接着npm login.
撤销发布的包
更新发布的包