cnpm 使用方案
1.常用命令
npm config list ls 列出当前变量
npm config list ls -l 列出当前所有变量
4.npm config相关的命令有
npm config set <key> <value>
npm config get [<key>]
npm config delete <key>
npm config list [--json]
npm config edit
npm set <key> <value>
npm get [<key>]
4.常用命令
npm list #列出当前目录下的所有模块, -g 列出全局模块
npm list express 列出 express 模块的详细信息
npm uninstall express 卸载模块
npm ls 列出模块
npm update express 更新模块
npm search express 搜索模块
npm init 使用 npm生成基本工程 包含了 package.json
npm adduser 增加用户
npm publish 发布模块
npm cache clear 清除缓存
npm whoami 查看当前登录用户
2.设置npm 代理与仓库
1.设置内网仓库
npm config set registry http://170.130.103.87:8081/repository/npm_grooup/
2.设置淘宝仓库地址
npm config set registry https://registry.npm.taobao.org
3.使用新的源下载 vue 组件包
npm i --loglevel info --registry=http://170.130.103.87:8081/repository/npm_grooup/
2.设置代理服务器
npm config set proxy http://170.101.103.6:3128
npm config set proxy null 清除代理设置
这个代理在内网一般不要设置 否者会报错可能原因是走的是服务器代理是https
npm config set https-proxy https://170.101.103.6:3128
npm config delete https-proxy 清除代理设置
#带用户名密码 设置代理
npm config set proxy http://username:password@server:port
npm config set https-proxy http://username:pawword@server:port
3.清除npm 代理服务器
npm config delete proxy
npm config delete https-proxy
3.本地安装与全局安装的区别
本地安装:
1. 将安装包放在 ./node_modules 下(运行 npm 命令时所在的目录),如果没有 node_modules 目录,会在当前执行 npm 命令的目录下生成 node_modules 目录。
2. 可以通过 require() 来引入本地安装的包。
全局安装:
1. 将安装包放在 /usr/local 下或者你 node 的安装目录。 (npm root -g)
2. 可以直接在命令行里使用。
4.上传npm包到私有仓库
1.注册nexus3 帐号 (找王震)
用户名 nexus
密码 nexus123
邮箱 1228857713@qq.com
2.登录 hosted仓库 需要使用用户名密码 就是注册到 nexus3 的帐号和密码
npm login --registry="http://170.130.103.87:8081/repository/npm_hosted_xyd/"
3.发布到 hosted仓库
npm publish --registry="http://170.130.103.87:8081/repository/npm_hosted_xyd/"
4. 删除在仓库上的jar
npm deprecate --registry="http://170.130.103.87:8081/repository/npm_hosted_xyd/" testproject1@0.0.1 "This package is deprecated"
#其他可能使用到的命令
cnpm adduser --registry="http://170.100.104.99:9002/repository/npm_hosted_xyd/"
5.注意如果上传报错 Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"
需要开启 relam 权限
http://170.130.103.87:8081/#admin/security/realms
把所有权限激活