前言
在前端开发过程中,node.js进行包管理的时候会使用npm管理器来操作。npm(node package manager)包管理器,主要是用于第三方模块的下载、安装和管理,它具有强大的第三方资源,重要程度不言而喻。
一、npm安装
npm安装步骤很简单,只用在终端里面输入一条命令行:apt-get isntall npm 回车,即可安装。
1、验证是否安装成功
安装npm之后,在终端输入运行命令行:npm serve 回车,查看是否安装成功,如果出现如下提示,就说明安装成功了,具体提示如下所示:
2、查看版本
ChenZeMacheng$ npm -v
6.13.4
ChenZeMac Cheng$ cnpm serve
Usage: npm <command>
where <command> is one of:
access, adduser, audit, bin, bugs, c, cache, ci, cit,
clean-install, clean-install-test, completion, config,
create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
edit, explore, fund, get, help, help-search, hook, i, init,
install, install-ci-test, install-test, it, link, list, ln,
login, logout, ls, org, outdated, owner, pack, ping, prefix,
profile, prune, publish, rb, rebuild, repo, restart, root,
run, run-script, s, se, search, set, shrinkwrap, star,
stars, start, stop, t, team, test, token, tst, un,
uninstall, unpublish, unstar, up, update, v, version, view,
whoami
npm <command> -h quick help on <command>
npm -l display full usage info
npm help <term> search for help on <term>
npm help npm involved overview
Specify configs in the ini-formatted file:
/Users/Cheng/.cnpmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config
[npm@6.13.6](https://link.juejin.cn?target=mailto%3Anpm%406.13.6 "mailto:npm@6.13.6") /ur/loal/lib/node_moules/cnpm/node_modules/npm
二、npm的使用
1、npm模式
npm有两个模式:全局模式和本地模式。
npm默认的是本地模式,该模式工作范围仅限于当前工作目录里面,在本地模式进行任何的操作都不会影响其他地方的node.js代码。
npm全局模式,顾名思义,就是对在电脑本机所有的node.js项目代码服务的,在全局模式进行操作只需操作一次可以使电脑本机上面所有的node.js项目都生效,所以要注意该模式的操作。
2、npm常用的命令
npm install 安装模块
npm uninstall 卸载模块
npm remove 移除模块
npm update 更新模块
npm outdated 检查模块是否已过时
npm ls 查看已安装的模块
npm help 查看某个命令行的详细帮助
npm root 查看包的安装路径
npm config 管理<strong>npm</strong>的配置路径
npm cache 管理模块的缓存
npm start 启动模块
npm stop 停止模块
npm restart 重新启动模块
npm test 测试模块
npm version 查看模块版本
npm view 查看模块的注册信息
npm adduser 用户登录
npm publish 发布模块
npm access 在发布的包上设置访问的级别
最后
通过本文对node.js的node包管理器npm安装以及使用的介绍,相比读者都会对相关内容有了更深刻的认识,对于刚入行前端不久的开发者来说掌握相关内容也是必备技能,对以后的工作也是有很大的帮助的,别的就不在多说。以上就是本章全部内容,欢迎关注三掌柜的微信公众号“程序猿by三掌柜”,三掌柜的新浪微博“三掌柜666”,欢迎关注!