得之我幸 失之我命

when someone abandons you,it is him that gets loss because he lost someone who truly loves him but you just lost one who doesn’t love you.

npm 换国内镜像源

每次 npm 安装一些包的时候,那个安装速度的体验真的是差透了,300M 的宽带,只有几十 k 的速度,那就换成国内镜像源吧,记录下

  1. 使用淘宝镜像

    1
    2
    3
    4
    5
    6
    7
    8
    # 临时使用
    $ npm --registry https://registry.npm.taobao.org install express

    # 持久使用
    $ npm config set registry https://registry.npm.taobao.org

    # 该用 cnpm,它的实质是 1.全局安装 cnpm 2.并且将安装包(各种包)的地址切换到国内的淘宝镜像,这个方案其实可以通过下方 4 的办法来进一步配合使用
    $ npm install -g cnpm --registry=https://registry.npm.taobao.org
  2. 使用官方镜像

    1
    $ npm config set registry https://registry.npmjs.org/
  3. 查看 npm 源地址

    1
    $ npm config get registry
  4. 使用第三方软件快速修改、切换 npm 镜像源

     nrm 不仅可以快速切换镜像源,还可以测试自己网络访问不同源的速度
    
    • 安装

      1
      $ npm install -g nrm
    • 列出当前可用的所有镜像源

      1
      2
      3
      4
      5
      6
      7
      8
      $ nrm ls

      npm ----- https://registry.npmjs.org/
      cnpm ---- http://r.cnpmjs.org/
      taobao -- https://registry.npm.taobao.org/
      nj ------ https://registry.nodejitsu.com/
      rednpm -- http://registry.mirror.cqupt.edu.cn
      skimdb -- https://skimdb.npmjs.com/registry
    • 选择任一镜像源,如 cnpm

      1
      $ nrm use cnpm
    • 测试访问速度

      1
      $ nrm test cnpm

be slow to promise and quick to perform.