Mac users can have three ways
one: Brew Way
Brew Install node
II: Manual Compilation
br> 1. Install Xcode
2. Install git
3. Run the following command line to compile Node.js
git clone git://github.com/joyent/node.git
CD NODE
/configure
Make
sudo make install
Three: Download pkg package install from official website
http://nodejs.org/# Download
Strongly recommend this type of installation Ah, because the above two I have tried the taste of failure
after installation with NODE-V can see the version number on the line
can also run the following demo
The code is as follows |
Copy Code |
var http = require (' http '); Http.createserver (function (req, res) { Res.writehead ({' Content-type ': ' Text/plain '}); Res.end (' Hello node.jsn '); }). Listen (8124, "127.0.0.1"); Console.log (' Server running at http://127.0.0.1:8124/');
|
Use node to run this piece of code
The code is as follows |
Copy Code |
Node Hello_node.js Server running at http://127.0.0.1:8124/ |
After installing Nodejs you need to install a NPM, similar to the GIM package in Ruby
Installation method is
Curl Http://npmjs.org/install.sh | sudo sh
PS: No sudo may not have permissions
Run NPM-V can see the version number on the line
Then you need to download the NODEJS MVC framework: Express
Install as a global installation:
NPM Install-g Express
And then use the EXPRESS-V to have the version number.
and use
Express Demo
You can create a demo of MVC,
CD Demo
NPM install-d
Node App.js
In this way, you can visit the http://localhost:3000 to see the successful page
Express
Welcome to Express
Maybe you're going to run into this damn anomaly.
Voidmatomacbook-air:hello2 voidman$ Node App.js
node.js:201
Throw e; Process.nexttick error, or ' Error ' event on tick
^
Typeerror:cannot Read property ' port ' of NULL
At Object. (/users/voidman/documents/workspace/hello2/app.js:35:76)
At Module._compile (module.js:441:26)
At Object.. JS (module.js:459:10)
At Module.load (module.js:348:31)
At Function._load (module.js:308:12)
At array.0 (module.js:479:10)
At Eventemitter._tickcallback (node.js:192:40)
There are two solutions, one of which is executing in the project root directory
NPM Install Express
No-g, so it can be installed under the Node_modules folder of the project
There is another way
NPM Install Express-g
If so, you will need to execute at the bottom of the project root directory
NPM install-d
to Insatall dependence.
There is also an exception is prompted Jade did not find, the solution is only necessary to install the Jade on the line
NPM install-g Jade