Quickly build a node. JS development environment and accelerate NPM
- How to quickly build a node development environment
- NPM Super Slow
- Issues that GitHub cannot open
So I think I should write an article to answer all these starting questions, so that the new students can also smooth the start.
Quickly build a node. JS development environment
If you want to do node development for a long time, or want to quickly update the node version, or if you want to switch node version quickly,
Then please use NVM to install your node development environment and keep the system clean.
git clone nvm
Directly from GitHub clone NVM to local, this assumes that everyone is using a ~/git
directory to store git projects:
$ cd ~/git $ git clone [https://github.com/creationix/nvm.git](https://github.com/creationix/nvm.git)
Configure the terminal to execute automatically when source ~/git/nvm/nvm.sh
it starts,
In,, ~/.bashrc
~/.bash_profile
~/.profile
, or ~/.zshrc
file, add the following command:
source ~/git/nvm/nvm.sh
Re-open your terminal, enternvm
$ NVM Node Version Manager USAGE:NVM help Show This message nvm--version Pr int out the latest released version of NVM NVM install [-S] <version> Download and install a <version> [-S] from source NVM uninstall <version> Uninstall a version nvm use <version> Modify PATH to use <version> nvm run <version> [<args>] Run <version> with <args> as argument S NVM current Display currently activated version NVM LS List installed ver sions NVM ls <version> List versions matching a given description nvm ls-remote L IST remote versions available for install NVM deactivate Undo effects of NVM in current shell NVM a Lias [<pattern>] Show all aliases beginning with <pattern> NVM alias <name> <version> Set an alias named <nAme> pointing to <version> nvm unalias <name> deletes the alias named <name> NVM C Opy-packages <version> Install Global NPM packages contained in <version> to current version Example:nv M install v0.10.24 install a specific version number NVM use 0.10 use the latest available 0.10 . x Release NVM run 0.10.24 myapp.js run myapp.js using node v0.10.24 NVM alias default 0.10.24 Set default Node version on a shell note:to remove, delete or uninstall Nvm-just remove ~/.NVM, ~/.NPM and ~/.bower folders
Install any version of node via NVM
NVM By default is downloaded from the http://nodejs.org/dist/, foreign servers, must be very slow,
Fortunately, NVM and the support to download the package from the mirror server, so we can easily from the seven Cow node dist image download:
$ NVM_NODEJS_ORG_MIRROR=[http://dist.u.qiniudn.com](http://dist.u.qiniudn.com/) nvm install 0.11.11
So you'll see a very fast progress bar:
###### ################################################################## 100.0%Now using node v0.11.11
If you do not want to enter the environment variable every time NVM_NODEJS_ORG_MIRROR
, then I recommend you to add to the .bashrc
file:
# nvmexport NVM_NODEJS_ORG_MIRROR=[http://dist.u.qiniudn.com](http://dist.u.qiniudn.com/) source ~/git/nvm/nvm.sh
Then you can continue to install each version of node very conveniently, and you can look at the version you are currently installing:
$ nvm ls nvm v0.8.26 v0.10.26 v0.11.11 -> v0.11.12
Accelerating NPM with CNPM
In the same vein, NPM defaults to acquiring and downloading package information from a foreign source, which is surprisingly slow.
You can use the ---registry
internal mirror http://r.cnpmjs.org by simple parameters:
$ npm --registry=[http://r.cnpmjs.org](http://r.cnpmjs.org/) install koa
So the screen again crashed a large output:
$ NPM--registry=[http://r.cnpmjs.org] (http://r.cnpmjs.org/) Install KOA npm http GET [Http://r.cnpmjs.org/koa] (http:/ /r.cnpmjs.org/koa) NPM http [Http://r.cnpmjs.org/koa] (Http://r.cnpmjs.org/koa) npm http GET [http://r.cnpmjs.org/ KOA/DOWNLOAD/KOA-0.5.2.TGZ] (http://r.cnpmjs.org/koa/download/koa-0.5.2.tgz) NPM http [http://r.cnpmjs.org/koa/ DOWNLOAD/KOA-0.5.2.TGZ] (http://r.cnpmjs.org/koa/download/koa-0.5.2.tgz) npm http GET [http://r.cnpmjs.org/ Escape-html] (http://r.cnpmjs.org/escape-html) npm http GET [http://r.cnpmjs.org/statuses] (http://r.cnpmjs.org/ Statuses) ... npm http [http://r.cnpmjs.org/negotiator] (http://r.cnpmjs.org/negotiator) NPM http [http://r.cnpm Js.org/keygrip] (Http://r.cnpmjs.org/keygrip) [[email protected]] (mailto:[email protected]) Node_ Modules/koa├──[[email protected]] (mailto:[email protected]) ├──[[email protected] (mailto:[email protected]) ├──[[email protected] [mailto:[email protected]) ├──[[email protected]] (mailto:[email protected]) ├──[[email protected] [mailto:[email protected]) ├──[[email Protected]] (mailto:[email protected]) ├──[[email protected] [mailto:[email protected]) ├──[[email protected]] (mailto:[email protected]) ├──[[email protected] [mailto:[email protected]) ├──[ [Email protected]] (mailto:[email protected]) ├──[[email protected] [mailto:[email protected]) ├──[[email Protected]] (mailto:[email protected]) ([[[Email protected]] (mailto:[email protected]) └──[[email protected]] (mailto:[email protected]) ([[email protected]] (mailto:[email protected])
But after all, the image and the official NPM source will still have a synchronization time difference, the current CNPM default synchronization time interval is 15 minutes.
If you are a module publisher, or if you want to sync a module right away, it is recommended that you install the CNPM CLI:
$ npm --registry=[http://r.cnpmjs.org](http://r.cnpmjs.org/) install cnpm -g
With the CNPM command line, you can quickly synchronize any module:
$ cnpm sync koa connect mocha
Well, I just don't want to install the CNPM CLI. Haha, I thought you would be so lazy, so we have a Web page:
For example I want to sync koa immediately, open the browser directly: Http://cnpmjs.org/sync/koa
Or you are command-line, open with the opening command:
$ open [http://cnpmjs.org/sync/koa](http://cnpmjs.org/sync/koa)
If you install a module that relies on C + + modules and needs to be compiled, it will certainly be compiled by NODE-GYP.
Node-gyp in the first compile time, need to rely on node source code, and then will go to node dist download,
So everyone will spit groove, how NPM installed so slow ...
OK, so we're going to refer to the --disturl
parameters, which are downloaded by the seven-ox image:
$ npm --registry=[http://r.cnpmjs.org](http://r.cnpmjs.org/) --disturl=[http://dist.u.qiniudn.com](http://dist.u.qiniudn.com/) install microtime
Again to refer to the CNPM CLI, which has been configured by default --registry
and --disturl
all well, who knows with whom
.
Quickly build a node. JS development environment and accelerate NPM