npm踩坑


)

一、常用命令

1.1 npm配置文件位置

npm config get userconfig

1.2 查看安装的包

npm list 包名

1.3 查看全局安装路径

npm root -g

1.4 查看局部安装路径

npm root

1.5 修改默认全局安装

  • 在配置文件中修改.npmrc
global = false

在这里插入图片描述

1.6 npm设置全局安装路径

npm config set prefix "D:\nodejs\node_global"

1.7 npm设置缓存路径

npm config set cache F:\software\nodejs\node_cache

1.8 读取npm包本地安装路径

npm root

1.9 npm读取prefix配置

npm config get prefix

1.10 查看npm位置

where npm

1.11 查看npm-cache

  • npm-cache不能随意更改路径不然会报错
$ npm config get cache
C:\Users\Administrator\AppData\Local\npm-cache

二、实战

2.1新建文件夹test1221

mkdir test1221

2.2 安装yarn

  • 如果文件没有node_modules文件夹和package.json文件,npm install会自动添加的
npm install yarn

在这里插入图片描述

2.3 查看yarn

$ npm list yarn
test1221@ C:\Users\Administrator\Desktop\test1221
`-- yarn@1.22.17

2.4 查看全局yarn的位置

$ npm list yarn -g
F:\software\nodejs\node_global
`-- (empty)

2.5 npm install yarn --save-dev

  • –save-dev
    工程构建(开发时、“打包”时)依赖
{
    
    
  "devDependencies": {
    
    
    "yarn": "^1.22.17"
  }
}

2.6 npm install solc–save

  • –save
    项目(运行时、发布到生产环境时)依赖
{
    
    
  "dependencies": {
    
    
    "solc": "^0.8.10"
  }
}

2.7 npm install xx

  • 不会写道package.json文件中

2.8 npm install --production

  • 只安装dependencies而不安装devDependencies。

猜你喜欢

转载自blog.csdn.net/qq_42306803/article/details/121353474
NPM