On the bus to brush micro-bo, or there are many students in consultation:
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 if you want to quickly update the node version, or if you want to switch node version quickly, use NVM to install your node development environment in a non-Windows (such as OSX, Linux) environment and keep the system Clean.
If you use Windows for development, you can use NVMW instead of NVM
OSX, Linux Environment
If you are developing Windows environment, please skip here and view the next chapter directly.
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
Configure the terminal to automatically execute at startup, in,, source ~/git/nvm/nvm.sh
~/.bashrc
~/.bash_profile
~/.profile
, or ~/.zshrc
file add the following command:
SOURCE ~/git/nvm/nvm.sh
Re-open your terminal, enternvm
$ nvmnode version managerusage: nvm help show this message nvm --version print 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>] &nbSp run <version> with <args> as arguments nvm current display currently activated version nvm ls list installed versions nvm ls <version> List versions matching a given description nvm ls-remote List remote versions available for install nvm deactivate undo effects of nvm on current shell nvm alias [< 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 copy-packages <version> Install global NPM packages contained in <version> to current versionExample: nvm 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 Shellnote: 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 http://nodejs.org/dist/, foreign servers, must be very slow, fortunately, NVM and support to download from the mirror server package, so we can easily from the seven Cow node dist image download:
$ nvm_nodejs_org_mirror=https://npm.taobao.org/dist 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=https://npm.taobao.org/distsource ~/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
Windows environment git clone NVMW
Directly from GitHub clone NVMW to local, this assumes that everyone uses a d:\git
directory to store git projects:
$ d:$ cd git$ git clone https://github.com/hakobera/nvmw.git
Set the d:\git\nvmw
directory to your PATH
environment variable:
Set "path=d:\git\nvmw;%path%"
Re-open your terminal, enternvmw
$ nvmwusage: nvmw help show this message nvmw install [version] download and install a [version] nvmw uninstall [version] uninstall a [version] nvmw use [version] modify path to use [version] nvmw ls List installed versionsexample: nvmw install v0.6.0 Install a specific version number nvmw use v0.6.0 use the specific version
Install any version of node via NVMW
NVMW By default is downloaded from http://nodejs.org/dist/, foreign servers, must be very slow, fortunately NVMW and support from the mirror server to download the package, so we can easily from the seven Cow node dist image download:
$ set "Nvmw_nodejs_org_mirror=https://npm.taobao.org/mirrors/node" $ nvmw Install 0.11.11
So you'll see a very fast progress bar:
######################################################################## 100.0%now using node v0.11.11
If you don't want to enter an environment variable every time NVMW_NODEJS_ORG_MIRROR
, then I recommend that you add it to the global environment variable.
Then you can continue to install each version of node very conveniently, and you can look at the version you are currently installing:
$ NVMW lsv0.10.26v0.11.12current:v0.11.12
This allows you to quickly install multiple versions of node, whether it's a Windows environment or OSX or Linux environments.
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 https://registry.npm.taobao.org by simple parameters:
$ npm--registry=https://registry.npm.taobao.org Install KOA
So the screen again crashed a large output:
$ npm --registry=https://registry.npm.taobao.org install koanpm http get https://registry.npm.taobao.org/koanpm http 200 https:// registry.npm.taobao.org/koa...npm http 200 https://registry.npm.taobao.org/negotiatornpm Http 200 https://registry.npm.taobao.org/keygripkoa[@0] (/user/0) .5.2 node_modules/koa├── Koa-compose[@2] (/USER/2). 2.0├── statuses[@1] (/USER/1). 0.2├── finished[@1] (/USER/1) .1.1├── Escape-html[@1] (/USER/1). 0.1├── only[@0] (/user/0). 0.2├── debug[@0] (/user/0). 8.0├── fresh[@0] (/ user/0). 2.2├── type-is[@1] (/USER/1). 0.1├── delegates[@0] (/user/0). 0.3├── mime[@1] (/USER/1). 2.11├──&NBSP;CO[@3] (/USER/3). 0.5├── accepts[@1] (/USER/1) .0.1 (negotiator[@0] (/user/0). 4.2) └── Cookies[@0] (/user/0) .4.0 (keygrip[@1] (/USER/1). 0.0)
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=https://registry.npm.taobao.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: Https://npm.taobao.org/sync/koa
Or you are command-line, open with the opening command:
$ open Https://npm.taobao.org/sync/koa
If you install the module depends on the C + + module, need to compile, will certainly be compiled through NODE-GYP, Node-gyp in the first compile, need to rely on node source code, and then will go to node dist Download, so we 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=https://registry.npm.taobao.org--disturl=https://npm.taobao.org/dist Install Microtime
Again to refer to the CNPM CLI, it has been configured by default --registry
and --disturl
all, who use who know. Write here, it is faster to doubt those who do not want to install the CNPM CLI and spit groove NPM slow classmate is based on what considerations do not install a cnpm locally?
GitHub is slow.
Well, see here you should have no slow problem with node and NPM.
GitHub is slow, or its resources host is blocked, and you can solve it by simply mapping the hosts:
185.31.16.184 github.global.ssl.fastly.net
Why is it so slow to visit a foreign site recently?
Heard is APCN2 and broken: Http://weibo.com/1415338244/ACTYkq8xK (APCN2 to repair for a long time)
Reprint: HTTPS://CNODEJS.ORG/TOPIC/5338C5DB7CBADE005B023C98
Quickly build a node. JS development environment and accelerate NPM