今天我们说几个简单实用npm命令~
安装 npm install 简写 npm i
卸载包 npm uninstall xxx
npmrc
.npmrc是npm的配置文件,可以定义在多个地方
~/.npmrc 用户根目录,根目录内所有的npm指令都会查询该配置
我们可以在npmrc配置username、registry、email等信息
registry=https://registry.npm.taobao.org
package.json文件配置
package.json是项目的配置管理文件,定义了这个项目所需要的各个依赖模块以及项目的配置信息(名字,版本号)
我们可以通过npm init初始化创建一个package.json文件
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"author": "",
"license": "",
"devDependencies": {
},
"dependencies": {
}
}
scripts
scripts定义了一些脚本指令的npm缩写 ,通过
main
main 指定项目加载的入口文件
keywords
keywords指定了在库中搜索时能被哪些关键字搜索到,所以一般会多写一些项目相关的词在这里,这是一个字符串数组。
查看镜像源
npm config get registry
查看配置列表
npm config list
查看所有的默认配置
npm config ls -l
设置镜像源 ( 镜像地址 https://registry.npm.taobao.org)
npm config set registry https://registry.npm.taobao.org
查看安装的modules
npm list
设置环境变量 可以指定使用某个版本的node (/home/work/env/node/node-v0.12.0-linux-x64/bin 为你nodd的版本)
export PATH=/home/work/env/node/node-v0.12.0-linux-x64/bin:$PATH