SlideShare a Scribd company logo
The Server-side JavaScript


                             Vikash Singh
WHAT TO EXPECT AHEADโ€ฆ.
๏‚ข Introduction
๏‚ข Some (Confusing) Theory

๏‚ข 5 Examples

๏‚ข A couple of weird diagrams

๏‚ข 2 Pics showing unbelievable benchmarks

๏‚ข Some stuff from Internet

๏‚ข And Homer Simpson
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 high-
  performance 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: ADVANCED (& CONFUSING)
๏‚ข 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 non-
  blocking 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.
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: 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.        Clients send HTTP requests
                       Client
                                      to Node.js server




Event loop returns                    An Event-loop is woken up by OS,
result to client                      passes request and response objects
                      Event loop      to the thread-pool
                      (main thread)

                                                Long-running jobs run
                                                on worker threads
                                 C++
Response is sent
                             Threadpool
back to main thread
                               (worker
via callback
                              threads)
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);
      });
    });
WHEN TO USE NODE.JS?
๏‚ข Node.js is good for creating streaming based real-
  time 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/how-
  to-decide-when-to-use-nodejs
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); });
    });
Introduction to Node.js
SOME NODE.JS BENCHMARKS
                                   Taken from:
                                   http://code.google.com/p/node-js-vs-apache-
                                   php-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-node-
  module-creators
Introduction to Node.js
Ad

More Related Content

What's hot (20)

JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
ย 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Ravi Teja
ย 
Expressjs
ExpressjsExpressjs
Expressjs
Yauheni Nikanovich
ย 
A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django Introduction
Ganga Ram
ย 
ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptx
DivyanshGupta922023
ย 
Advanced Web Development
Advanced Web DevelopmentAdvanced Web Development
Advanced Web Development
Robert J. Stein
ย 
Ajax ppt
Ajax pptAjax ppt
Ajax ppt
OECLIB Odisha Electronics Control Library
ย 
React JS - A quick introduction tutorial
React JS - A quick introduction tutorialReact JS - A quick introduction tutorial
React JS - A quick introduction tutorial
Mohammed Fazuluddin
ย 
Introduction of Html/css/js
Introduction of Html/css/jsIntroduction of Html/css/js
Introduction of Html/css/js
Knoldus Inc.
ย 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
Arnold Asllani
ย 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
ๆดช ้นๅ‘
ย 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
Arulmurugan Rajaraman
ย 
Reactjs
Reactjs Reactjs
Reactjs
Neha Sharma
ย 
Nodejs functions & modules
Nodejs functions & modulesNodejs functions & modules
Nodejs functions & modules
monikadeshmane
ย 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
shreesenthil
ย 
Learn react-js
Learn react-jsLearn react-js
Learn react-js
C...L, NESPRESSO, WAFAASSURANCE, SOFRECOM ORANGE
ย 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
Gabriele Lana
ย 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
Vikas Jagtap
ย 
jQuery
jQueryjQuery
jQuery
Dileep Mishra
ย 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
Apaichon Punopas
ย 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
ย 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Ravi Teja
ย 
A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django Introduction
Ganga Ram
ย 
ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptx
DivyanshGupta922023
ย 
Advanced Web Development
Advanced Web DevelopmentAdvanced Web Development
Advanced Web Development
Robert J. Stein
ย 
React JS - A quick introduction tutorial
React JS - A quick introduction tutorialReact JS - A quick introduction tutorial
React JS - A quick introduction tutorial
Mohammed Fazuluddin
ย 
Introduction of Html/css/js
Introduction of Html/css/jsIntroduction of Html/css/js
Introduction of Html/css/js
Knoldus Inc.
ย 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
Arnold Asllani
ย 
Reactjs
Reactjs Reactjs
Reactjs
Neha Sharma
ย 
Nodejs functions & modules
Nodejs functions & modulesNodejs functions & modules
Nodejs functions & modules
monikadeshmane
ย 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
shreesenthil
ย 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
Gabriele Lana
ย 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
Apaichon Punopas
ย 

Viewers also liked (6)

Node ppt
Node pptNode ppt
Node ppt
Tamil Selvan R S
ย 
Anatomy of a Modern Node.js Application Architecture
Anatomy of a Modern Node.js Application Architecture Anatomy of a Modern Node.js Application Architecture
Anatomy of a Modern Node.js Application Architecture
AppDynamics
ย 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
Jussi Pohjolainen
ย 
The Enterprise Case for Node.js
The Enterprise Case for Node.jsThe Enterprise Case for Node.js
The Enterprise Case for Node.js
NodejsFoundation
ย 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
Manish Bothra
ย 
Node Foundation Membership Overview 20160907
Node Foundation Membership Overview 20160907Node Foundation Membership Overview 20160907
Node Foundation Membership Overview 20160907
NodejsFoundation
ย 
Anatomy of a Modern Node.js Application Architecture
Anatomy of a Modern Node.js Application Architecture Anatomy of a Modern Node.js Application Architecture
Anatomy of a Modern Node.js Application Architecture
AppDynamics
ย 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
Jussi Pohjolainen
ย 
The Enterprise Case for Node.js
The Enterprise Case for Node.jsThe Enterprise Case for Node.js
The Enterprise Case for Node.js
NodejsFoundation
ย 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
Manish Bothra
ย 
Node Foundation Membership Overview 20160907
Node Foundation Membership Overview 20160907Node Foundation Membership Overview 20160907
Node Foundation Membership Overview 20160907
NodejsFoundation
ย 
Ad

Similar to Introduction to Node.js (20)

Introduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comIntroduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.com
Van-Duyet Le
ย 
Proposal
ProposalProposal
Proposal
Constantine Priemski
ย 
Nodejs
NodejsNodejs
Nodejs
Vinod Kumar Marupu
ย 
Node
NodeNode
Node
Ankit Chawla
ย 
Nodejs
NodejsNodejs
Nodejs
dssprakash
ย 
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
ย 
Introduction to Node.JS
Introduction to Node.JSIntroduction to Node.JS
Introduction to Node.JS
Collaboration Technologies
ย 
Day In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperDay In A Life Of A Node.js Developer
Day In A Life Of A Node.js Developer
Edureka!
ย 
Day in a life of a node.js developer
Day in a life of a node.js developerDay in a life of a node.js developer
Day in a life of a node.js developer
Edureka!
ย 
An overview of node.js
An overview of node.jsAn overview of node.js
An overview of node.js
valuebound
ย 
Node js
Node jsNode js
Node js
Chirag Parmar
ย 
Node.js: A Guided Tour
Node.js: A Guided TourNode.js: A Guided Tour
Node.js: A Guided Tour
cacois
ย 
node.js.pptx
node.js.pptxnode.js.pptx
node.js.pptx
rani marri
ย 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDD
Sudar Muthu
ย 
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
ย 
Node JS Interview Question PDF By ScholarHat
Node JS Interview Question PDF By ScholarHatNode JS Interview Question PDF By ScholarHat
Node JS Interview Question PDF By ScholarHat
Scholarhat
ย 
Node js beginner
Node js beginnerNode js beginner
Node js beginner
Sureshreddy Nalimela
ย 
unit 2 of Full stack web development subject
unit 2 of Full stack web development subjectunit 2 of Full stack web development subject
unit 2 of Full stack web development subject
JeneferAlan1
ย 
Introduction to node.js By Ahmed Assaf
Introduction to node.js  By Ahmed AssafIntroduction to node.js  By Ahmed Assaf
Introduction to node.js By Ahmed Assaf
Ahmed Assaf
ย 
Ferrara Linux Day 2011
Ferrara Linux Day 2011Ferrara Linux Day 2011
Ferrara Linux Day 2011
Gianluca Padovani
ย 
Introduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comIntroduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.com
Van-Duyet Le
ย 
Nodejs
NodejsNodejs
Nodejs
dssprakash
ย 
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
ย 
Day In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperDay In A Life Of A Node.js Developer
Day In A Life Of A Node.js Developer
Edureka!
ย 
Day in a life of a node.js developer
Day in a life of a node.js developerDay in a life of a node.js developer
Day in a life of a node.js developer
Edureka!
ย 
An overview of node.js
An overview of node.jsAn overview of node.js
An overview of node.js
valuebound
ย 
Node.js: A Guided Tour
Node.js: A Guided TourNode.js: A Guided Tour
Node.js: A Guided Tour
cacois
ย 
node.js.pptx
node.js.pptxnode.js.pptx
node.js.pptx
rani marri
ย 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDD
Sudar Muthu
ย 
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
ย 
Node JS Interview Question PDF By ScholarHat
Node JS Interview Question PDF By ScholarHatNode JS Interview Question PDF By ScholarHat
Node JS Interview Question PDF By ScholarHat
Scholarhat
ย 
unit 2 of Full stack web development subject
unit 2 of Full stack web development subjectunit 2 of Full stack web development subject
unit 2 of Full stack web development subject
JeneferAlan1
ย 
Introduction to node.js By Ahmed Assaf
Introduction to node.js  By Ahmed AssafIntroduction to node.js  By Ahmed Assaf
Introduction to node.js By Ahmed Assaf
Ahmed Assaf
ย 
Ferrara Linux Day 2011
Ferrara Linux Day 2011Ferrara Linux Day 2011
Ferrara Linux Day 2011
Gianluca Padovani
ย 
Ad

Recently uploaded (20)

Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
ย 
Image processinglab image processing image processing
Image processinglab image processing  image processingImage processinglab image processing  image processing
Image processinglab image processing image processing
RaghadHany
ย 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
ย 
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
Lynda Kane
ย 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
ย 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
ย 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
ย 
Leading AI Innovation As A Product Manager - Michael Jidael
Leading AI Innovation As A Product Manager - Michael JidaelLeading AI Innovation As A Product Manager - Michael Jidael
Leading AI Innovation As A Product Manager - Michael Jidael
Michael Jidael
ย 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
ย 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
ย 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
ย 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
ย 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
ย 
Automation Dreamin' 2022: Sharing Some Gratitude with Your Users
Automation Dreamin' 2022: Sharing Some Gratitude with Your UsersAutomation Dreamin' 2022: Sharing Some Gratitude with Your Users
Automation Dreamin' 2022: Sharing Some Gratitude with Your Users
Lynda Kane
ย 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
ย 
Salesforce AI Associate 2 of 2 Certification.docx
Salesforce AI Associate 2 of 2 Certification.docxSalesforce AI Associate 2 of 2 Certification.docx
Salesforce AI Associate 2 of 2 Certification.docx
Josรฉ Enrique Lรณpez Rivera
ย 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
ย 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
ย 
"PHP and MySQL CRUD Operations for Student Management System"
"PHP and MySQL CRUD Operations for Student Management System""PHP and MySQL CRUD Operations for Student Management System"
"PHP and MySQL CRUD Operations for Student Management System"
Jainul Musani
ย 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
ย 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
ย 
Image processinglab image processing image processing
Image processinglab image processing  image processingImage processinglab image processing  image processing
Image processinglab image processing image processing
RaghadHany
ย 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
ย 
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
Lynda Kane
ย 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
ย 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
ย 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
ย 
Leading AI Innovation As A Product Manager - Michael Jidael
Leading AI Innovation As A Product Manager - Michael JidaelLeading AI Innovation As A Product Manager - Michael Jidael
Leading AI Innovation As A Product Manager - Michael Jidael
Michael Jidael
ย 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
ย 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
ย 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
ย 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
ย 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
ย 
Automation Dreamin' 2022: Sharing Some Gratitude with Your Users
Automation Dreamin' 2022: Sharing Some Gratitude with Your UsersAutomation Dreamin' 2022: Sharing Some Gratitude with Your Users
Automation Dreamin' 2022: Sharing Some Gratitude with Your Users
Lynda Kane
ย 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
ย 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
ย 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
ย 
"PHP and MySQL CRUD Operations for Student Management System"
"PHP and MySQL CRUD Operations for Student Management System""PHP and MySQL CRUD Operations for Student Management System"
"PHP and MySQL CRUD Operations for Student Management System"
Jainul Musani
ย 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
ย 

Introduction to Node.js

  • 2. WHAT TO EXPECT AHEADโ€ฆ. ๏‚ข Introduction ๏‚ข Some (Confusing) Theory ๏‚ข 5 Examples ๏‚ข A couple of weird diagrams ๏‚ข 2 Pics showing unbelievable benchmarks ๏‚ข Some stuff from Internet ๏‚ข And Homer Simpson
  • 3. 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.
  • 4. INTRODUCTION: BASIC ๏‚ข In simple words Node.js is โ€˜server-side JavaScriptโ€™. ๏‚ข In not-so-simple words Node.js is a high- performance 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!)
  • 5. INTRODUCTION: ADVANCED (& CONFUSING) ๏‚ข 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 non- blocking 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.
  • 6. 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โ€™
  • 7. 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. Clients send HTTP requests Client to Node.js server Event loop returns An Event-loop is woken up by OS, result to client passes request and response objects Event loop to the thread-pool (main thread) Long-running jobs run on worker threads C++ Response is sent Threadpool back to main thread (worker via callback threads)
  • 8. 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!
  • 9. 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.
  • 10. 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");
  • 11. 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.
  • 12. 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); }); });
  • 13. WHEN TO USE NODE.JS? ๏‚ข Node.js is good for creating streaming based real- time 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/how- to-decide-when-to-use-nodejs
  • 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); }); });
  • 16. SOME NODE.JS BENCHMARKS Taken from: http://code.google.com/p/node-js-vs-apache- php-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.
  • 17. 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-
  • 18. 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
  • 19. 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!
  • 20. 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-node- module-creators