npm的使用

npm的使用

npm不用专门下载,会随着node的下载,自动安装.

npm命令

1.淘宝镜像设置

  • 使用cnpm来下载,项目打包会和npm发生冲突
npm install -g cnpm --registry=https://registry.npm.taobao.org
  • 使用npm来下载,但是改变npm指向(从原本的境外指向转变为指向淘宝),不会发生冲突
npm config set registry https://registry.npm.taobao.org

2.查看版本

npm -v

3.安装模块

npm install 包名 --save      添加到dependencies(项目依赖)项目上线时候需要用到的包   简写可以使用 -S (简写必须是大写) 项目打包时会一起打包
npm install 包名 --save-dev  添加到devDependencies(开发依赖)  开发代码时使用的包,例如测试,验证等使用的模块和包      简写可以使用 -D (简写必须大写) 不打包,需要自己另外下载
npm install 包名 -global    全局安装,任何一个项目都可以访问到    可以使用简写 -g

4.删除模块

npm uninstall 包名
npm uninstall 包名 -g   删除全局安装的模块
npm uninstall 包名 --save或者npm uninstall 包名 -S    删除项目依赖的模块
npm uninstall 包名 --save-dev或者npm uninstall 包名 -D     删除开发依赖的模块

5.清除缓存 这种情况一般出现:模块下载途中,断网了 或者 模块下载后不能正常使用

npm cache verify
-4048

6.重设代理

错误内容    ECONNREFUSED     一直连接不上
察看代理    npm config get proxy     npm config get https-proxy    如果不是null
设置代理    npm config set proxy null      npm config set https-proxy null

7.npm 初始化 会生成package.json(打包配置文件)

npm  init  -y

8.执行脚本 (执行package.json文件内script中的具体内容)

npm run test  执行脚本中的test

原文地址:https://www.cnblogs.com/94-Lucky/p/13447898.html