NPM
.npmrc
NPM的配置文件
registry=https://registry.npmjs.org/
package-lock=false # 不启用NPM锁
命令
npm config
npm config set registry https://registry.npmjs.org/
npm config get prefix
npm config delete registry
npm config
npm init
初始化package.json
npm init -y
npm install
npm install <name> --save # yarn add <name>
npm install <name> --save-dev # yarn add <name> -D
npm install -g <name> # yarn global add <name>
npm install
npm ci # 通常用于CI,使用该命令时需要确保项目中存在 package-lock.json或 npm-shrinkwrap.json,并且当 package.json和 package-lock.json中依赖的版本不一致时 npm ci会抛出错误。
本地安装时,模块会被安装在/project/node_modules下,同时如果该模块的package.json中存在bin字段时,则会自动根据bin表示的字 典在/project/node_modules/.bin下面创建对应的符号链接。
全局安装时,模块会被安装在/usr/local/lib/node_modules(以MacOS举例)下,同时如果该模块的package.json中存在bin字段时,则会自动根据bin表示的字典在/usr/local/bin下面创建对应的符号链接(可理解为Windows中的快捷方式)。
举个例子,akara-project的package.json中的bin字段如下,那么当全局安装akara-project时会创建/usr/local/bin/akara这个文件(符号链接),这个文件实际指向着akara-project根路径下的index.js。(其实这就是开发命令行工具的原理)
{
"bin": {
"akara": "index.js"
}
}
npm uninstall
npm uninstall <name> # yarn remove <name>