# NodeJS 的使用

2 min read
Table of Contents

遇到的 NodeJS 的使用情况,如全局全文,清除缓存,指定缓存目录等。

全局

官方主要提供了两种解决方案:

  • 使用 node 版本管理工具安装(推荐)
  • 手动修改 npm 默认目录

版本管理工具可以简单快速切换到不同的 node 版本,极大方便了开发和测试。

OSX 和 Linux

Windows

手动修改

  1. 创建文件夹

    Terminal window
    mkdir ~/.npm-global
  2. 配置 npm

    Terminal window
    npm config set prefix '~/.npm-global'
  3. 打开/新建 ~/.profile,增加以下的命令

    Terminal window
    export PATH=~/.npm-global/bin:$PATH
  4. 更新系统变量

    Terminal window
    source ~/.profile

参考链接

缓存相关

清除缓存包:

  • 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

More Posts

# TSConfig参考

3 min read

TSConfig 文件位于项目的根目录下,TSConfig 文件可以是 tsconfig.json 或 jsconfig.json。