SlideShare a Scribd company logo
The Server-side JavaScript

Constantine Priemski
BACKGROUND
V8 is an open source JavaScript engine developed
by Google. Its written in C++ and is used in Google
Chrome Browser.
 Node.js runs on V8.
 It was created by Ryan Dahl in 2009.
 Is still in Beta phase. Latest version is 0.6.11
 Is Open Source. It runs well on Linux systems, can
also run on Windows systems.
 If you have worked on EventMachine (Ruby) or
Python’s Twisted or Perl’s AnyEvent framework
then following presentation is going to be very easy.

INTRODUCTION: BASIC
In simple words Node.js is ‘server-side
JavaScript’.
 In not-so-simple words Node.js is a highperformance network applications
framework, well optimized for high concurrent
environments.
 It’s a command line tool.
 In ‘Node.js’ , ‘.js’ doesn’t mean that its solely written
JavaScript. It is 40% JS and 60% C++.
 From the official site:


‘Node's goal is to provide an easy way to build
scalable network programs’ - (from nodejs.org!)
INTRODUCTION
Node.js uses an event-driven, non-blocking I/O
model, which makes it lightweight. (from
nodejs.org!)
 It makes use of event-loops via JavaScript’s
callback functionality to implement the nonblocking I/O.
 Programs for Node.js are written in JavaScript but
not in the same JavaScript we are use to. There is
no DOM implementation provided by Node.js, i.e.
you can not do this:


var element = document.getElementById(‚elementId‛);


Everything inside Node.js runs in a single-thread.
INTRODUCTION: ASYNC, NON-BLOCK, EVENTBASE








Asynchronous Asynchronous literally means not synchronous. Email is
asynchronous. You send a mail, you don't expect to get a response NOW. But it is
not non-blocking. Essentially what it means is an architecture where "components"
send messages to each other without expecting a response immediately. HTTP
requests are synchronous. Send a request and get a response.
Non-Blocking This term is mostly used with IO. What this means is that when you
make a system call, it will return immediately with whatever result it has without
putting your thread to sleep (with high probability). For example non-blocking
read/write calls return with whatever they can do and expect caller to execute the
call again. try_lock for example is non-blocking call. It will lock only if lock can be
acquired. Usual semantics for systems calls is blocking. read will wait until it has
some data and put calling thread to sleep.
Event-base This term comes from libevent. non-blocking read/write calls in
themselves are useless because they don't tell you "when" should you call them
back (retry). select/epoll/IOCompletionPort etc are different mechanisms for finding
out from OS "when" these calls are expected to return "interesting" data. libevent
and other such libraries provide wrappers over these event monitoring facilities
provided by various OSes and give a consistent API to work with which runs
across operating systems. Non-blocking IO goes hand in hand with Event-base.
I think these terms overlap. For example HTTP protocol is synchronous but HTTP
implementation using non-blocking IO can be asynchronous. Again a non-blocking
API call like read/write/try_lock is synchronous (it immediately gives a response)
but "data handling" is asynchronous.
SOME THEORY: EVENT-LOOPS


Event-loops are the core of event-driven programming,
almost all the UI programs use event-loops to track the
user event, for example: Clicks, Ajax Requests etc.
Client

Event loop returns
result to client

Event loop

Clients send HTTP requests
to Node.js server

An Event-loop is woken up by OS,
passes request and response objects
to the thread-pool

(main thread)

Long-running jobs run
on worker threads
Response is sent
back to main thread
via callback

C++
Threadpool
(worker
threads)
WHEN TO USE NODE.JS?
Node.js is good for creating streaming based realtime services, web chat applications, static file
servers etc.
 If you need high level concurrency and not worried
about CPU-cycles.
 If you are great at writing JavaScript code because
then you can use the same language at both the
places: server-side and client-side.
 More can be found at:
http://stackoverflow.com/questions/5062614/howto-decide-when-to-use-nodejs

EXAMPLE-1: GETTING STARTED & HELLO
WORLD


Install/build Node.js.


(Yes! Windows installer is available!)

Open your favorite editor and start typing
JavaScript.
 When you are done, open cmd/terminal and type
this:
‘node YOUR_FILE.js’
 Here is a simple example, which prints ‘hello world’


var sys = require(‚sys‛);
setTimeout(function(){
sys.puts(‚world‛);},3000);
sys.puts(‚hello‛);
//it prints ‘hello’ first and waits for 3 seconds and then
prints ‘world’
SOME THEORY: NON-BLOCKING I/O


Traditional I/O
var result = db.query(‚select x from table_Y‛);
doSomethingWith(result); //wait for result!
doSomethingWithOutResult(); //execution is blocked!



Non-traditional, Non-blocking I/O
db.query(‚select x from table_Y”,function (result){
doSomethingWith(result); //wait for result!
});
doSomethingWithOutResult(); //executes without any
delay!
WHAT CAN YOU DO WITH NODE.JS ?
You can create an HTTP server and print ‘hello
world’ on the browser in just 4 lines of JavaScript.
(Example included)
 You can create a TCP server similar to HTTP
server, in just 4 lines of JavaScript. (Example
included)
 You can create a DNS server.
 You can create a Static File Server.
 You can create a Web Chat Application like GTalk
in the browser.
 Node.js can also be used for creating online
games, collaboration tools or anything which sends
updates to the user in real-time.

EXAMPLE -2 &3 (HTTP SERVER & TCP
SERVER)


Following code creates an HTTP Server and prints
‘Hello World’ on the browser:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello Worldn'); }).listen(5000, "127.0.0.1");



Here is an example of a simple TCP server which
listens on port 6000 and echoes whatever you send
it:
var net = require('net');
net.createServer(function (socket) {
socket.write("Echo serverrn");
socket.pipe(socket); }).listen(6000, "127.0.0.1");
NODE.JS ECOSYSTEM
Node.js heavily relies on modules, in previous
examples require keyword loaded the http & net
modules.
 Creating a module is easy, just put your JavaScript
code in a separate js file and include it in your code
by using keyword require, like:


var modulex = require(‘./modulex’);


Libraries in Node.js are called packages and they
can be installed by typing
npm install ‚package_name‛; //package should be
available in npm registry @ nmpjs.org



NPM (Node Package Manager) comes bundled
with Node.js installation.
EXAMPLE-4: LETS CONNECT TO A DB
(MONGODB)


Install mongojs using npm, a mongoDB driver for
Node.js
npm install mongojs



Code to retrieve all the documents from a collection:
var db = require("mongojs")
.connect("localhost:27017/test", ['test']);
db.test.find({}, function(err, posts) {
if( err || !posts) console.log("No posts found");
else posts.forEach( function(post) {
console.log(post);
});
});
EXAMPLE-5: TWITTER STREAMING


Install nTwitter module using npm:
Npm install ntwitter



Code:
var twitter = require('ntwitter');
var twit = new twitter({
consumer_key: ‘c_key’,
consumer_secret: ‘c_secret’,
access_token_key: ‘token_key’,
access_token_secret: ‘token_secret’});
twit.stream('statuses/sample', function(stream) {
stream.on('data', function (data) {
console.log(data); });
});
SOME NODE.JS BENCHMARKS
Taken from:
http://code.google.com/p/node-js-vs-apachephp-benchmark/wiki/Tests

A benchmark between Apache+PHP
and node.js, shows the response
time for 1000 concurrent connections
making 10,000 requests each, for 5
tests.

Taken from:
http://nodejs.org/jsconf2010.pdf

The benchmark shows the
response time in milli-secs
for 4 evented servers.
WHEN TO NOT USE NODE.JS








When you are doing heavy and CPU intensive
calculations on server side, because event-loops are
CPU hungry.
Node.js API is still in beta, it keeps on changing a lot
from one revision to another and there is a very little
backward compatibility. Most of the packages are also
unstable. Therefore is not yet production ready.
Node.js is a no match for enterprise level application
frameworks like
Spring(java), Django(python), Symfony(php) etc.
Applications written on such platforms are meant to be
highly user interactive and involve complex business
logic.
Read further on disadvantages of Node.js on Quora:
http://www.quora.com/What-are-the-disadvantages-of-
APPENDIX-1: WHO IS USING NODE.JS IN
PRODUCTION?
Yahoo! : iPad App Livestand uses Yahoo!
Manhattan framework which is based on Node.js.
 LinkedIn : LinkedIn uses a combination of Node.js
and MongoDB for its mobile platform. iOS and
Android apps are based on it.
 eBay : Uses Node.js along with ql.io to help
application developers in improving eBay’s end
user experience.
 Dow Jones : The WSJ Social front-end is written
completely in Node.js, using Express.js, and many
other modules.
 Complete list can be found at:
https://github.com/joyent/node/wiki/Projects,Applications,-and-Companies-Using-Node

APPENDIX-2: RESOURCE TO GET STARTED
Watch this video at Youtube:
http://www.youtube.com/watch?v=jo_B4LTHi3I
 Read the free O’reilly Book ‘Up and Running with
Node.js’ @
http://ofps.oreilly.com/titles/9781449398583/
 Visit www.nodejs.org for Info/News about Node.js
 Watch Node.js tutorials @ http://nodetuts.com/
 For Info on MongoDB:
http://www.mongodb.org/display/DOCS/Home
 For anything else Google!

APPENDIX-3: SOME GOOD MODULES
Express – to make things simpler e.g. syntax, DB
connections.
 Jade – HTML template system
 Socket.IO – to create real-time apps
 Nodemon – to monitor Node.js and push change
automatically
 CoffeeScript – for easier JavaScript development
 Find out more about some widely used Node.js
modules at: http://blog.nodejitsu.com/top-nodemodule-creators

Proposal

More Related Content

What's hot

Nuxt.js - Introduction
Nuxt.js - IntroductionNuxt.js - Introduction
Nuxt.js - Introduction
Sébastien Chopin
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
Joseph de Castelnau
 
Introduction to asp.net
Introduction to asp.netIntroduction to asp.net
Introduction to asp.net
SHADAB ALI
 
Learn REST in 18 Slides
Learn REST in 18 SlidesLearn REST in 18 Slides
Learn REST in 18 Slides
Suraj Gupta
 
Rest API
Rest APIRest API
Introduction Node.js
Introduction Node.jsIntroduction Node.js
Introduction Node.js
Erik van Appeldoorn
 
Php
PhpPhp
Introduction to html course digital markerters
Introduction to html course digital markertersIntroduction to html course digital markerters
Introduction to html course digital markerters
SEO SKills
 
Introduction to REST - API
Introduction to REST - APIIntroduction to REST - API
Introduction to REST - API
Chetan Gadodia
 
REST-API introduction for developers
REST-API introduction for developersREST-API introduction for developers
REST-API introduction for developers
Patrick Savalle
 
An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST API
Aniruddh Bhilvare
 
Modern Java web applications with Spring Boot and Thymeleaf
Modern Java web applications with Spring Boot and ThymeleafModern Java web applications with Spring Boot and Thymeleaf
Modern Java web applications with Spring Boot and Thymeleaf
LAY Leangsros
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
Apaichon Punopas
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
Dinesh U
 
Nodejs presentation
Nodejs presentationNodejs presentation
Nodejs presentation
Arvind Devaraj
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
Joshua Long
 
Web development | Derin Dolen
Web development | Derin Dolen Web development | Derin Dolen
Web development | Derin Dolen
Derin Dolen
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
Akshay Mathur
 

What's hot (20)

Php Presentation
Php PresentationPhp Presentation
Php Presentation
 
Nuxt.js - Introduction
Nuxt.js - IntroductionNuxt.js - Introduction
Nuxt.js - Introduction
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 
Introduction to asp.net
Introduction to asp.netIntroduction to asp.net
Introduction to asp.net
 
Learn REST in 18 Slides
Learn REST in 18 SlidesLearn REST in 18 Slides
Learn REST in 18 Slides
 
Rest API
Rest APIRest API
Rest API
 
Introduction Node.js
Introduction Node.jsIntroduction Node.js
Introduction Node.js
 
Php
PhpPhp
Php
 
Introduction to html course digital markerters
Introduction to html course digital markertersIntroduction to html course digital markerters
Introduction to html course digital markerters
 
Introduction to REST - API
Introduction to REST - APIIntroduction to REST - API
Introduction to REST - API
 
REST-API introduction for developers
REST-API introduction for developersREST-API introduction for developers
REST-API introduction for developers
 
An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST API
 
Modern Java web applications with Spring Boot and Thymeleaf
Modern Java web applications with Spring Boot and ThymeleafModern Java web applications with Spring Boot and Thymeleaf
Modern Java web applications with Spring Boot and Thymeleaf
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Nodejs presentation
Nodejs presentationNodejs presentation
Nodejs presentation
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Web development | Derin Dolen
Web development | Derin Dolen Web development | Derin Dolen
Web development | Derin Dolen
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
 
Asp.net
 Asp.net Asp.net
Asp.net
 

Viewers also liked

CT Signature PP
CT Signature PPCT Signature PP
CT Signature PP
Timothy Eugene
 

Viewers also liked (7)

Tornado my
Tornado myTornado my
Tornado my
 
CT Signature PP
CT Signature PPCT Signature PP
CT Signature PP
 
Yourprezi
YourpreziYourprezi
Yourprezi
 
Birthdayz
BirthdayzBirthdayz
Birthdayz
 
Rich
RichRich
Rich
 
Zuzia
ZuziaZuzia
Zuzia
 
Polish boys team
Polish boys teamPolish boys team
Polish boys team
 

Similar to Proposal

Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Vikash Singh
 
Kalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect GuideKalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect Guide
Kalp Corporate
 
Nodejs
NodejsNodejs
Node
NodeNode
Introduction to Node.JS
Introduction to Node.JSIntroduction to Node.JS
Introduction to Node.JS
Collaboration Technologies
 
Nodejs
NodejsNodejs
Nodejs
dssprakash
 
Introduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comIntroduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.com
Van-Duyet Le
 
Node Session - 1
Node Session - 1Node Session - 1
Node Session - 1
Bhavin Shah
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginners
Enoch Joshua
 
Node
NodeNode
Node.js: A Guided Tour
Node.js: A Guided TourNode.js: A Guided Tour
Node.js: A Guided Tour
cacois
 
Best node js course
Best node js courseBest node js course
Best node js course
bestonlinecoursescoupon
 
Beginners Node.js
Beginners Node.jsBeginners Node.js
Beginners Node.js
Khaled Mosharraf
 
Node Js Non-blocking or asynchronous Blocking or synchronous.pdf
Node Js Non-blocking or asynchronous  Blocking or synchronous.pdfNode Js Non-blocking or asynchronous  Blocking or synchronous.pdf
Node Js Non-blocking or asynchronous Blocking or synchronous.pdf
DarshanaMallick
 
Nodejs
NodejsNodejs
Building Applications With the MEAN Stack
Building Applications With the MEAN StackBuilding Applications With the MEAN Stack
Building Applications With the MEAN Stack
Nir Noy
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
David Padbury
 
An overview of node.js
An overview of node.jsAn overview of node.js
An overview of node.js
valuebound
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN StackRob Davarnia
 

Similar to Proposal (20)

Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Kalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect GuideKalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect Guide
 
Nodejs
NodejsNodejs
Nodejs
 
Node
NodeNode
Node
 
Introduction to Node.JS
Introduction to Node.JSIntroduction to Node.JS
Introduction to Node.JS
 
Nodejs
NodejsNodejs
Nodejs
 
Introduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comIntroduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.com
 
Node Session - 1
Node Session - 1Node Session - 1
Node Session - 1
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginners
 
Node js
Node jsNode js
Node js
 
Node
NodeNode
Node
 
Node.js: A Guided Tour
Node.js: A Guided TourNode.js: A Guided Tour
Node.js: A Guided Tour
 
Best node js course
Best node js courseBest node js course
Best node js course
 
Beginners Node.js
Beginners Node.jsBeginners Node.js
Beginners Node.js
 
Node Js Non-blocking or asynchronous Blocking or synchronous.pdf
Node Js Non-blocking or asynchronous  Blocking or synchronous.pdfNode Js Non-blocking or asynchronous  Blocking or synchronous.pdf
Node Js Non-blocking or asynchronous Blocking or synchronous.pdf
 
Nodejs
NodejsNodejs
Nodejs
 
Building Applications With the MEAN Stack
Building Applications With the MEAN StackBuilding Applications With the MEAN Stack
Building Applications With the MEAN Stack
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
 
An overview of node.js
An overview of node.jsAn overview of node.js
An overview of node.js
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
 

Recently uploaded

How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 

Recently uploaded (20)

How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 

Proposal

  • 2. BACKGROUND V8 is an open source JavaScript engine developed by Google. Its written in C++ and is used in Google Chrome Browser.  Node.js runs on V8.  It was created by Ryan Dahl in 2009.  Is still in Beta phase. Latest version is 0.6.11  Is Open Source. It runs well on Linux systems, can also run on Windows systems.  If you have worked on EventMachine (Ruby) or Python’s Twisted or Perl’s AnyEvent framework then following presentation is going to be very easy. 
  • 3. INTRODUCTION: BASIC In simple words Node.js is ‘server-side JavaScript’.  In not-so-simple words Node.js is a highperformance network applications framework, well optimized for high concurrent environments.  It’s a command line tool.  In ‘Node.js’ , ‘.js’ doesn’t mean that its solely written JavaScript. It is 40% JS and 60% C++.  From the official site:  ‘Node's goal is to provide an easy way to build scalable network programs’ - (from nodejs.org!)
  • 4. INTRODUCTION Node.js uses an event-driven, non-blocking I/O model, which makes it lightweight. (from nodejs.org!)  It makes use of event-loops via JavaScript’s callback functionality to implement the nonblocking I/O.  Programs for Node.js are written in JavaScript but not in the same JavaScript we are use to. There is no DOM implementation provided by Node.js, i.e. you can not do this:  var element = document.getElementById(‚elementId‛);  Everything inside Node.js runs in a single-thread.
  • 5. INTRODUCTION: ASYNC, NON-BLOCK, EVENTBASE     Asynchronous Asynchronous literally means not synchronous. Email is asynchronous. You send a mail, you don't expect to get a response NOW. But it is not non-blocking. Essentially what it means is an architecture where "components" send messages to each other without expecting a response immediately. HTTP requests are synchronous. Send a request and get a response. Non-Blocking This term is mostly used with IO. What this means is that when you make a system call, it will return immediately with whatever result it has without putting your thread to sleep (with high probability). For example non-blocking read/write calls return with whatever they can do and expect caller to execute the call again. try_lock for example is non-blocking call. It will lock only if lock can be acquired. Usual semantics for systems calls is blocking. read will wait until it has some data and put calling thread to sleep. Event-base This term comes from libevent. non-blocking read/write calls in themselves are useless because they don't tell you "when" should you call them back (retry). select/epoll/IOCompletionPort etc are different mechanisms for finding out from OS "when" these calls are expected to return "interesting" data. libevent and other such libraries provide wrappers over these event monitoring facilities provided by various OSes and give a consistent API to work with which runs across operating systems. Non-blocking IO goes hand in hand with Event-base. I think these terms overlap. For example HTTP protocol is synchronous but HTTP implementation using non-blocking IO can be asynchronous. Again a non-blocking API call like read/write/try_lock is synchronous (it immediately gives a response) but "data handling" is asynchronous.
  • 6. SOME THEORY: EVENT-LOOPS  Event-loops are the core of event-driven programming, almost all the UI programs use event-loops to track the user event, for example: Clicks, Ajax Requests etc. Client Event loop returns result to client Event loop Clients send HTTP requests to Node.js server An Event-loop is woken up by OS, passes request and response objects to the thread-pool (main thread) Long-running jobs run on worker threads Response is sent back to main thread via callback C++ Threadpool (worker threads)
  • 7. WHEN TO USE NODE.JS? Node.js is good for creating streaming based realtime services, web chat applications, static file servers etc.  If you need high level concurrency and not worried about CPU-cycles.  If you are great at writing JavaScript code because then you can use the same language at both the places: server-side and client-side.  More can be found at: http://stackoverflow.com/questions/5062614/howto-decide-when-to-use-nodejs 
  • 8. EXAMPLE-1: GETTING STARTED & HELLO WORLD  Install/build Node.js.  (Yes! Windows installer is available!) Open your favorite editor and start typing JavaScript.  When you are done, open cmd/terminal and type this: ‘node YOUR_FILE.js’  Here is a simple example, which prints ‘hello world’  var sys = require(‚sys‛); setTimeout(function(){ sys.puts(‚world‛);},3000); sys.puts(‚hello‛); //it prints ‘hello’ first and waits for 3 seconds and then prints ‘world’
  • 9. SOME THEORY: NON-BLOCKING I/O  Traditional I/O var result = db.query(‚select x from table_Y‛); doSomethingWith(result); //wait for result! doSomethingWithOutResult(); //execution is blocked!  Non-traditional, Non-blocking I/O db.query(‚select x from table_Y”,function (result){ doSomethingWith(result); //wait for result! }); doSomethingWithOutResult(); //executes without any delay!
  • 10. WHAT CAN YOU DO WITH NODE.JS ? You can create an HTTP server and print ‘hello world’ on the browser in just 4 lines of JavaScript. (Example included)  You can create a TCP server similar to HTTP server, in just 4 lines of JavaScript. (Example included)  You can create a DNS server.  You can create a Static File Server.  You can create a Web Chat Application like GTalk in the browser.  Node.js can also be used for creating online games, collaboration tools or anything which sends updates to the user in real-time. 
  • 11. EXAMPLE -2 &3 (HTTP SERVER & TCP SERVER)  Following code creates an HTTP Server and prints ‘Hello World’ on the browser: var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Worldn'); }).listen(5000, "127.0.0.1");  Here is an example of a simple TCP server which listens on port 6000 and echoes whatever you send it: var net = require('net'); net.createServer(function (socket) { socket.write("Echo serverrn"); socket.pipe(socket); }).listen(6000, "127.0.0.1");
  • 12. NODE.JS ECOSYSTEM Node.js heavily relies on modules, in previous examples require keyword loaded the http & net modules.  Creating a module is easy, just put your JavaScript code in a separate js file and include it in your code by using keyword require, like:  var modulex = require(‘./modulex’);  Libraries in Node.js are called packages and they can be installed by typing npm install ‚package_name‛; //package should be available in npm registry @ nmpjs.org  NPM (Node Package Manager) comes bundled with Node.js installation.
  • 13. EXAMPLE-4: LETS CONNECT TO A DB (MONGODB)  Install mongojs using npm, a mongoDB driver for Node.js npm install mongojs  Code to retrieve all the documents from a collection: var db = require("mongojs") .connect("localhost:27017/test", ['test']); db.test.find({}, function(err, posts) { if( err || !posts) console.log("No posts found"); else posts.forEach( function(post) { console.log(post); }); });
  • 14. EXAMPLE-5: TWITTER STREAMING  Install nTwitter module using npm: Npm install ntwitter  Code: var twitter = require('ntwitter'); var twit = new twitter({ consumer_key: ‘c_key’, consumer_secret: ‘c_secret’, access_token_key: ‘token_key’, access_token_secret: ‘token_secret’}); twit.stream('statuses/sample', function(stream) { stream.on('data', function (data) { console.log(data); }); });
  • 15. SOME NODE.JS BENCHMARKS Taken from: http://code.google.com/p/node-js-vs-apachephp-benchmark/wiki/Tests A benchmark between Apache+PHP and node.js, shows the response time for 1000 concurrent connections making 10,000 requests each, for 5 tests. Taken from: http://nodejs.org/jsconf2010.pdf The benchmark shows the response time in milli-secs for 4 evented servers.
  • 16. WHEN TO NOT USE NODE.JS     When you are doing heavy and CPU intensive calculations on server side, because event-loops are CPU hungry. Node.js API is still in beta, it keeps on changing a lot from one revision to another and there is a very little backward compatibility. Most of the packages are also unstable. Therefore is not yet production ready. Node.js is a no match for enterprise level application frameworks like Spring(java), Django(python), Symfony(php) etc. Applications written on such platforms are meant to be highly user interactive and involve complex business logic. Read further on disadvantages of Node.js on Quora: http://www.quora.com/What-are-the-disadvantages-of-
  • 17. APPENDIX-1: WHO IS USING NODE.JS IN PRODUCTION? Yahoo! : iPad App Livestand uses Yahoo! Manhattan framework which is based on Node.js.  LinkedIn : LinkedIn uses a combination of Node.js and MongoDB for its mobile platform. iOS and Android apps are based on it.  eBay : Uses Node.js along with ql.io to help application developers in improving eBay’s end user experience.  Dow Jones : The WSJ Social front-end is written completely in Node.js, using Express.js, and many other modules.  Complete list can be found at: https://github.com/joyent/node/wiki/Projects,Applications,-and-Companies-Using-Node 
  • 18. APPENDIX-2: RESOURCE TO GET STARTED Watch this video at Youtube: http://www.youtube.com/watch?v=jo_B4LTHi3I  Read the free O’reilly Book ‘Up and Running with Node.js’ @ http://ofps.oreilly.com/titles/9781449398583/  Visit www.nodejs.org for Info/News about Node.js  Watch Node.js tutorials @ http://nodetuts.com/  For Info on MongoDB: http://www.mongodb.org/display/DOCS/Home  For anything else Google! 
  • 19. APPENDIX-3: SOME GOOD MODULES Express – to make things simpler e.g. syntax, DB connections.  Jade – HTML template system  Socket.IO – to create real-time apps  Nodemon – to monitor Node.js and push change automatically  CoffeeScript – for easier JavaScript development  Find out more about some widely used Node.js modules at: http://blog.nodejitsu.com/top-nodemodule-creators 