
安装nodejs后的相关准备工作-npm-nvm
安装nodejs后的npm相关准备工作
由于重装系统,需要重新安装nodejs,故需重新配置npm环境
设置国内镜像
- npm config set registry http://registry.npm.taobao.org/ 【x】
- npm config set registry https://registry.npmmirror.com/
- npm config set registry http://mirrors.cloud.tencent.com/npm/
- npm config set registry https://registry.npmjs.org/ #恢复镜像
安装yarn
- npm i yarn -g
- yarn config set registry http://registry.npm.taobao.org/【x】
- yarn config set registry https://registry.npmmirror.com/
其他cnpm、pnpm:
- npm i cnpm -g
- npm i pnpm -g
设置npm代理(仅内网访问外网情况下)
公司内网环境要使用外网镜像一般需要设置代理
- npm config set strict-ssl false # 关闭npm的https
- npm config set proxy http://user:password@proxyhk.xxx.com:8080 # http://ip:prot
NVM版本管理
nvm 全名叫做 nodejs version manage,管理nodejs版本
https://github.com/coreybutler/nvm-windows/releases
1 |
|
安装后,必须为每个已安装的node版本重新安装全局包,例如yarn
1 |
|
node常用命令
1 |
|
npm包发布
注册npm账号 https://www.npmjs.com/
1 |
|
注意:
packge.json中name字段确保唯一性,并配置各字段
使用npm官方源登录
npm config set registry https://registry.npmjs.org/
1 |
|
也可以配置github的Actions自动发布
私有npm仓库
使用Verdaccio搭建,基于Node.js
https://www.npmjs.com/package/verdaccio
1 |
|
FAQ
yarn : 无法加载文件 C:\Users\Administrator\AppData\Roaming\npm\yarn.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
- 运行 Windows PowerShell(管理员)【win10 可直接 shift+鼠标右键,然后打开窗口,若不行,可看 powershell安装和使用】
- 执行命令【set-ExecutionPolicy RemoteSigned】更改 PowerShell 执行策略,
过程中提示询问是否要更改执行策略?,选择 【A】 或 Y