11
Introduction to Node.JS Pragnesh Vaghela | @technologythree | technologythree.com

Introduction to Node js

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 2: Introduction to Node js

@ 2013 Technology Three 2

Problemwhat’s a really common thing to do in a web application? Database access, of course. Too bad database I/O is one of the slowest things a web app has to deal with

data = readFromDatabase();printData(data);

doSomethingUnrelated();

asynchronous JavaScript:

readFromDatabase(function(data) { printData(data);})

doSomethingUnrelated();

Page 3: Introduction to Node js

@ 2013 Technology Three 3

NODE.JS

1. platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications

2. perfect for data-intensive real-time applications that run across distributed devices

Page 4: Introduction to Node js

@ 2013 Technology Three 4

NODE.JS

1. server-side JavaScript framework - the same type of code that powers awesome Ajax applications like Gmail will now power its servers, too

2. driven by asynchronous design - that it doesn’t have to wait for slow file I/O or database operations to continue processing, which makes it really damn fast. It also means that it can handle millions of concurrent connections at once

3. real-time applications - you do not have to bother with low-level sockets and protocols

Page 5: Introduction to Node js

@ 2013 Technology Three 5

Bad Use Cases

1. apps that are very heavy on CPU usage, and very light on actual I/O - video encoding software, artificial intelligence or similar CPU hungry software

2. simple CRUD / HTML apps

Page 6: Introduction to Node js

@ 2013 Technology Three 6

Good Use Cases• JSON APIs

building light-weight REST / JSON api's is something where node.js really shines. Its non-blocking I/O model combined with JavaScript make it a great choice for wrapping other data sources such as databases or web services and exposing them via a JSON interface

• Single page Appsif you are planning to write an AJAX heavy single page app (think gmail), node.js is a great fit as well. The ability to process many requests / seconds with low response times, as well as sharing things like validation code between the client and server make it a great choice for modern web applications that do lots of processing on the client

Page 7: Introduction to Node js

@ 2013 Technology Three 7

Good Use Cases

• Streaming dataone great example is parsing file uploads in real time, as well as building proxies between different data layers

• Soft Realtime Applicationseasy to develop soft real time systems like twitter, chat software, sport bets or interfaces to instant messaging networks

Page 8: Introduction to Node js

@ 2013 Technology Three 8

Example Web Servervar http = require('http');

http.createServer(function (request, response) { response.writeHead(200, {'Content-Type': 'text/plain'}); response.end('Hello World\n');}).listen(8124);

console.log('Server running at http://127.0.0.1:8124/');

To run the server, put the code into a file called example.js and execute it with the node program:

> node example.jsServer running at http://127.0.0.1:8124/

Page 9: Introduction to Node js

@ 2013 Technology Three 9

Real world Node.JS Applications

Page 10: Introduction to Node js

@ 2013 Technology Three 10

NODE.JS in the industry1. CBS, Linkedin use Node.js for mobile2. Walmart’s Node-powered mobile app front-end code

gets executed on the back end3. Yahoo has released some things for Node, and supports

cocktails - a Node.js platform. It also uses Node.js in the livestand infrastructure

4. Mozilla has implemented Node.js to support browser APIs which has half a billion installs

5. Pinterest uses Node as a webserver in some instances6. Ebay hosts their HTTP API service with Node7. HP uses Node for their WebOS initiatives