开发nodejs前需要知道的一些东西

@#$SDFG$DEW#E@!EXWT#ߥ®™∞¡¥

  • github无法访问下不了
  • node.js环境搭建好慢
  • npm慢死
  • bower慢
  • BLABLABLA……

node.js环境快速搭建管理

直接从 github clone nvm 到本地, 这里假设大家都使用 ~/git 目录存放 git 项目:

$ cd ~/git
$ git clone https://github.com/creationix/nvm.git

配置终端启动时自动执行 source ~/git/nvm/nvm.sh,
在 ~/.bashrc, ~/.bash_profile, ~/.profile, 或者 ~/.zshrc 文件添加以下命令:

$ source ~/git/nvm/nvm.sh

nvm 默认是从 http://nodejs.org/dist/ 下载的, 国外服务器, 必然很慢,
好在 nvm 以及支持从镜像服务器下载包, 于是我们可以方便地从七牛的 node dist 镜像下载:

$ NVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/dist nvm install 0.11.11

于是你就会看到一段非常快速进度条:

######################################################################## 100.0%
Now using node v0.11.11

如果你不想每次都输入环境变量 NVM_NODEJS_ORG_MIRROR, 那么我建议你加入到 .bashrc 文件中:

# nvm
export NVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/dist
source ~/git/nvm/nvm.sh

nvm 的具体使用我在这里就不多说了,其他人讲的挺多了,官网也很详尽,或者直接nvm回车查看帮助

使用镜像或者cnpm加速npm

同理 nvm , npm 默认是从国外的源获取和下载包信息, 不慢才奇怪.
可以通过简单的 ---registry 参数, 使用国内的镜像 https://registry.npm.taobao.org :

$ npm --registry=https://registry.npm.taobao.org install nrm
//华为云镜像
$npm config set registry https://mirrors.huaweicloud.com/repository/npm/

当然, 每次都要输入那么长串的 registry url 的话, 实在太麻烦, 可以使用 nrm 这个模块来切换镜像:

$ nrm ls
// 对比各个镜像的访问速度
$ nrm test
// 使用淘宝的镜像
$ nrm use taobao

但是毕竟镜像跟官方的 npm 源还是会有一个同步时间差异, 目前 cnpm 的默认同步时间间隔是 15 分钟.
如果你是模块发布者, 或者你想马上同步一个模块, 那么推荐你安装 cnpm cli:

npm install cnpm -g

安装时需要root权限。通过 cnpm 命令行, 你可以快速同步任意模块:

$ cnpm install xxx

呃, 我就是不想安装 cnpm cli 怎么办? 哈哈, 早就想到你会这么懒了, 于是我们还有一个 web 页面:

例如我想马上同步 koa, 直接打开浏览器: https://npm.taobao.org/sync/koa

或者你是命令行控, 通过 open 命令打开:

$ open https://npm.taobao.org/sync/koa

如果你安装的模块依赖了 C++ 模块, 需要编译, 肯定会通过 node-gyp 来编译,

node-gyp 在第一次编译的时候, 需要依赖 node 源代码, 于是又会去 node dist 下载,

于是大家又会吐槽, 怎么 npm 安装这么慢…

好吧, 于是又要提到 —disturl 参数, 通过七牛的镜像来下载:

$ npm --registry=https://registry.npm.taobao.org --disturl=https://npm.taobao.org/dist install microtime

再次要提到 cnpm cli, 它已经默认将 —registry 和 —disturl 都配置好了, 用了就知道了.

GitHub好慢啊

好了, 看到这里大家应该对 node 和 npm 已经没有速度慢的问题了.

github 慢, 或者说是它的资源 host 被堵而已, 大家可以通过简单的 hosts 映射解决:

185.31.16.184 github.global.ssl.fastly.net

国内taobao镜像列表

bower添加代理

修改 .bowerrc 文件(如无则新增):

{
  "proxy": "http://hx.gy:1080",
  "https-proxy": "http://hx.gy:1080"
}

代理

你懂的能访问就好,不懂多搜就懂

阅读余下内容
 

2条回应:“开发nodejs前需要知道的一些东西”

  1. FREE ITUNES CARDS 2018

    ====

    FREE ITUNES CARDS 2018
    ITUNES GIFT CARD CODE 2018
    FREE ITUNES GIFT CARD 2018
    ITUNES CARD CODES 2018
    FREE ITUNES GIFT CARD CODES 2018
    FREE ITUNES CODES 2018
    FREE ITUNES MONEY 2018
    FREE APPLE GIFT CARD 2018
    FREE ITUNES GIFT CARD CODES NO SURVEYS 2018
    ITUNES GIFT CARD GENERATOR 2018
    ITUNES GIFT CARD APP 2018
    FREE ITUNES CARD CODES 2018
    GET FREE ITUNES GIFT CARD 2018
    FREE ITUNES CARD REDEEM CODE 2018

    of of selecting a contraception method without sacrificing mood of data. Apple is now scheduling an finish date for paid iTunes music downloads, based upon sources inside the company REDEEM ITUNES present CARD ONLINE 2018. Apple Music is not broken subsequent to restore. To learn further practically Apple’s iTunes U program, absorb go to their web site. One code, tens of millions of how to enjoy it. Use the App amassing & iTunes recompense code to get apps, video games, music, movies and TELEVISION shows.

    Placing into observe this sturdy ASO (App heap Optimization) strategy comforts you certainly to reinforce your software positions and minister to you later than natural free ITUNES gift CARD CODES NO HUMAN avowal 2018 App amassing Downloads. Music organizing software program has saved me from spending hours of my activity sorting my iTunes.

    ITUNES REEDEM CODES 2018
    REDEEM ITUNES GIFT CARD 2018
    ITUNES REDEEM CODE FREE 2018
    FREE ITUNES CARD REDEEM CODE 2018
    APPLE ITUNES GIFT CARD CODES 2018
    REDEEM ITUNES GIFT CARD ONLINE 2018
    FREE ITUNES GIFT CARD NO SURVEY 2018
    FREE ITUNES GIFT CARD GENERATOR 2018
    FREE ITUNES GIFT CARD CODES THAT WORK 2018
    FREE ITUNES CARD REDEEM CODE 2018
    FREE ITUNES GIFT CARD CODES NO HUMAN VERIFICATION 2018
    HOW TO WIN ITUNES GIFT CARDS 2018
    FREE ITUNES CODES LIST 2018
    FREE ITUNES CODES 2018 NOT USED
    FREE ITUNES GIFT CARD NO SURVEY NO HUMAN VERIFICATION 2018
    FREE ITUNES GIFT CARD CODES NO SURVEYS OR OFFERS 2018
    ITUNES GIFT CARD GENERATOR NO HUMAN VERIFICATION 2018
    FREE ITUNES CODES NO HUMAN VERIFICATION OR SURVEYS 2018
    FREE ITUNES GIFT CARD CODES GENERATOR 2018
    FREE ITUNES CODES NO HUMAN VERIFICATION NO SURVEY 2018
    FREE ITUNES CODES NOT USED 2018
    ITUNES GIFT CARD CODES THAT ALWAYS WORK 2018
    ITUNES GIFT CARD CODES FREE 2018
    ITUNES GIFT CARD CODES UNUSED 2018
    FREE ITUNES GIFT CARD CODES THAT WORK 2018
    FREE ITUNES GIFT CARD CODES NO SURVEYS NO VERIFICATION 2018
    FREE ITUNES GIFT CARD CODES 2018 NO SURVEYS
    EARN ITUNES GIFT CARDS WATCHING VIDEOS 2018
    EARN ITUNES GIFT CARDS FAST 2018
    FREE ITUNES GIFT CARD 2018
    HOW TO GET FREE ITUNES GIFT CARDS LEGALLY 2018
    HOW TO WIN ITUNES GIFT CARDS PRIZE WHEEL 2018
    FREE ITUNES GIFT CARD NO HUMAN VERIFICATION 2018
    FREE ITUNES CODES GENERATOR 2018
    FREE ITUNES CODES LIST 2018
    FREE ITUNES CODES 2018
    FREE ITUNES CODES 2018 NOT USED
    FREE ITUNES CODES NO HUMAN VERIFICATION 2018
    APPLE GIFT CARD 2018
    FREE APPLE GIVEAWAY 2018
    FREE APPLE GIFT CARD 2018
    APPLE GIFT CARD CODES 2018
    APPLE GIFT CARD REDEEM 2018
    ITUNES GIFT CARD ONLINE 2018
    FREE APPLE MACBOOK AIR GIVEAWAY 2018
    FREE APPLE GIFT CARD CODES NO SURVEY 2018
    FREE ITUNES GIFT CARD GENERATOR 2018
    FREE ITUNES GIFT CARD CODES THAT WORK 2018
    FREE ITUNES CARD REDEEM CODE 2018
    FREE ITUNES GIFT CARD NO HUMAN VERIFICATION 2018
    ITUNES GIFT CARD CODES UNUSED 2018
    ITUNES GIFT CARD CODE HACK 2018
    ITUNES GIFT CARD CODE FREE LIST 2018

发表评论

电子邮件地址不会被公开。 必填项已用*标注


京ICP备12002735号