NodeJS 的使用
2020 nodejs遇到的 NodeJS 的使用情况,如全局全文,清除缓存,指定缓存目录等。
全局
官方主要提供了两种解决方案:
- 使用 node 版本管理工具安装(推荐)
- 手动修改 npm 默认目录
版本管理工具可以简单快速切换到不同的 node 版本,极大方便了开发和测试。
OSX 和 Linux
Windows
手动修改
-
创建文件夹
mkdir ~/.npm-global
-
配置 npm
npm config set prefix '~/.npm-global'
-
打开/新建
~/.profile
,增加以下的命令export PATH=~/.npm-global/bin:$PATH
-
更新系统变量
source ~/.profile
参考链接
- 官方解决方案
Resolving EACCES permissions errors when installing packages globally - Downloading and installing Node.js and npm
缓存相关
清除缓存包:
npm cache clean --force
yarn cache clean
查询 yarn 缓存目录:
yarn cache dir
指定 yarn 缓存目录:
yarn config set cache-folder <path>
yarn config get cache-folder D:\\Yarn\\Cache
查询 yarn 缓存列表:
yarn cache list