Rising from non-existence a few short years ago, Node.js is already attracting the accolades and disdain enjoyed and endured by the Ruby and Rails community just a short time ago. It overtook Rails as the most popular Github repository in 2011 and was selected by InfoWorld for the Technology of the Year Award in 2012. This presentation explains the basic theory and programming model central to Node's approach and will help you understand the resulting benefits and challenges it presents. You can also watch this presentation at http://bit.ly/1362UGA
2. Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network
applications. Node.js uses an event driven, non-blocking I/O model that makes it lightweight and
efficient, perfect for data-intensive real-time applications that run across distributed devices.
DOWNLOAD DOCS
v0.6.11
15. HTTP Server
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello Worldn');
}).listen(8124);
console.log('Server running at http://127.0.0.1:8124/');
16. Serve a Static File
var http = require('http');
http.createServer(function (request, response) {
fs.readFile('/etc/passwd', function (err, data) {
if (err) {
response.writeHead(500, err.message);
response.end();
} else {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end(data);
}
});
}).listen(8124);
17. Read a File in Chunks
var fs = require('fs');
var stream = fs.createReadStream('huge.txt');
stream.on('data', function (data) {
console.log(data);
});
stream.on('end', function () {
console.log('done');
});
stream.on('error', function (err) {
console.log(err);
});