new kid on the block node.js

14
New Kid On The Block – Node.js Joel Divekar GM – Information Systems, People Interactive (I) Pvt. Ltd. Open Source Conference, Pune 23 rd March, 2013

Upload: joel-divekar

Post on 19-May-2015

2.180 views

Category:

Technology


0 download

DESCRIPTION

This presentation was presented by at ‘Open source Conference’, Pune, India organised by SiliconIndia on 23rd March 2013.

TRANSCRIPT

Page 1: New kid on the block node.js

New Kid On The Block – Node.js

Joel DivekarGM – Information Systems,People Interactive (I) Pvt. Ltd.Open Source Conference, Pune23rd March, 2013

Page 2: New kid on the block node.js

Node.js was developed by Ryan Dhal in 2009

and the project is managed by Joyent

Page 3: New kid on the block node.js

Node.js is ...

Server side JavaScript

Event Driven

Asynchronous I/O

Single Threaded

Lightweight

Page 4: New kid on the block node.js

Node.js ...

High performance network application framework and can

easily handle thousands of concurrent connections with

minimum CPU / Memory Utilisation

Built on top of Google's V8 JavaScript engine used in

Chrome

Easy to build scalable network servers

Page 5: New kid on the block node.js

Node.js is similar to ...

EventMachine in Ruby

Twisted in Python

Page 6: New kid on the block node.js

I/O

Blocking I/O

var fs = require('fs');

var file1 = fs.readFileSync('File1.txt', 'utf-8');

console.log(“Reading File1.txt”);

var file2 = readFileSync('File2.txt', 'utf-8');

console.log(“Reading File2.txt”);

Non-Blocking I/O

var fs = require('fs');

fs.readFileSync('File1.txt', 'utf-8', function(err,data){

console.log(“Reading File1.txt”)

});

fs.readFileSync('File2.txt', 'utf-8', function(err,data){

console.log(“Reading File2.txt”)

});

Page 7: New kid on the block node.js

I/O

Blocking I/O

Reading File1.txt took 10 ms

Reading File2.txt took 6 ms

Total time 16 ms

Non-Blocking I/O

Reading File1.txt took 10 ms

Reading File2.txt took 6 ms

Total time 10 ms

Page 8: New kid on the block node.js

Callback

//callback after 2 seconds

setTimeout(function(){

console.log(“World”);

}, 2000);

console.log(“Hello”);

Page 9: New kid on the block node.js

Node REPL

REPL : Read - Eval - Print - Loop$ node

> a=[1,2,"3",'four',];

[ 1, 2, '3', 'four' ]

> a.forEach(function (v) {

... console.log(v);

... });

1

2

3

four

Undefined

> .exit

Page 10: New kid on the block node.js

Node.js HTTP Server

var http = require("http");

http.createServer(function(req, res) {

req.on("end", function () {

res.writeHead(200, {'Content-Type' : 'text/plain'});

res.end('Your IP is ' + (req.headers['x-forwarded-for'] || req.connection.remoteAddress) + '!') });

}).listen(8080);

console.log("Server accepting request on http://127.0.0.1:8080");

Page 11: New kid on the block node.js

Node.js HTTP Server

var http = require("http");

http.createServer(function(req, res) {

req.on("end", function () {

res.writeHead(200, {'Content-Type' : 'text/plain'});

res.end('Your IP is ' + (req.headers['x-forwarded-for'] || req.connection.remoteAddress) + '!') });

}).listen(8080);

console.log("Server accepting request on http://127.0.0.1:8080");

Page 12: New kid on the block node.js

npm

npm is package manager for node.js, similar to RubyGems & Python easy_install

npm install <module_name>

Modules

Express – MVC framework

Socket.IO – Websocket Library

Page 13: New kid on the block node.js

Who is using Node.js ...

Page 14: New kid on the block node.js

Thanks a lot for your time …

[email protected]/in/joeldivekar

joeldivekar.blogspot.comwww.slideshare.net/JoelDivekar