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>