初面网初面网

Node

注:阿里镜像地址已变更

https://registry.npmmirror.com

换源

全局安装cnpm并指定源为阿里

npm install -g cnpm --registry=https://registry.npm.taobao.org 

将源设置为阿里云

npm config set registry "https://registry.npmmirror.com" 
  • node-sass的问题

在更新node-sass中,有时候也会出现资源下载不了的问题,通常是git上的资源下载不了,这时候,可以更改node-sass的资源路径为淘宝的 npm config set sass_binary_site=https://npm.taobao.org/mirrors/node-sass/

phantomjs的源

npm config set phantomjs_cdnurl=https://npm.taobao.org/mirrors/phantomjs/ 

electron源

npm config set electron_mirror=https://npm.taobao.org/mirrors/electron/

设置目录

  • 获取全局缓存目录
npm config get cache
npm config get prefix
  • 设置全局安装目录(路径为参考。应设置为自己的路径)
npm config set cache "D:\nodejs\node_cache"
npm config set prefix "D:\nodejs\node_global"

设置环境

我们可以在启动的时候加上启动环境,如:

"prod": "cross-env NODE_ENV=production pm2 app.js"

其中,cross-env是第三方模块,需要下载

npm i cross-env

NODE_ENV是环境设置,production意味着是生产环境(正式环境)

pm2是启动用的第三方模块,也需要下载

npm i pm2

关于Yarn换源

如果您使用的是Yarn,它的换源命令如下:

yarn config set registry https://registry.npm.taobao.org --global

yarn的默认地址是: https://registry.yarnpkg.com

查看当前源的命令如下:

yarn config get registry

查看缓存地址

npm get cache
yarn cache dir
pnpm store path

清理缓存

下面是普通的清理。末尾再添加--force则是强制清理。

npm cache clean
yarn cache clean
pnpm store prune

强制清理示例:

npm cache clean --force

查看某个依赖所有可用版本

npm view [包名] versions

更新于 2025/2/26