Build & Install node.js from source code
0
Following instructions are tested on Ubuntu 10.04 & node v0.12.2 download node package from http://nodejs.org/dist/latest/ tar -xvzf node-v0.12.2.tar.gz cd node-v0.12.2 Run the following commands
1 2 3 |
./configure make sudo make install |
To test the install
1 2 3 4 |
~$ node > (^C again to quit) > |
Hello World Test! vi hello.node.js
1 |
console.log("Hello, World!") |
To Run,
1 |
node hello.node.js |
Let’s do something more than Hello World.
1 |
vi http.test.js |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
var http = require("http"); http.createServer(function (request, response) { // Send HTTP Status: 200 : OK // Content Type: text/plain response.writeHead(200, {'Content-Type': 'text/plain'}); // Send the response body as "Hello World" response.end('Hello World\n'); }).listen(8888); // Console will print the message console.log('Server running at http://127.0.0.1:8888/'); |
To test the above code
1 2 |
On a Console: node http.test.js On a Web browser: http://127.0.0.1:8888 |