SlideShare a Scribd company logo
1 of 21
An Introduction to Node.JS Sudar Muthu (@sudarmuthu) Research Engineer Yahoo Labs http://sudarmuthu.com
Agenda What Node.JS is What Node.JS is not Why Node.JS? Using Node.JS As a interactive shell As a Server As a Client Common Modules Terminologies Questions
What is Node.JS Provides Evented, non-blocking I/O Built on Google’s V8 JavaScript Programming Environment Supports C/C++ based addons Supports CommonJS Module format Is fast .. infact very fast.
What is Node.JS Similar to  EventMachine in Ruby Twisted in Python    But provides Evented IO as part of the language construct itself and not as a library.
Node.JS is not … Ruby on Rails Django Codeigniter Node.JS is bare bone and the community are making stuff like Express, connect etc.
Why Node.JS? Code like this var result = db.query("select.."); // use result either blocks the entire process or implies multiple execution stacks (threads).
Why Node.JS? But a line of code like this db.query("select..", function (result) {       // use result }); allows the program to return to the event loop immediately. No more unnecessary threads.
Demo of Callback // execute the callback after 2 seconds setTimeout(function () { console.log("World!"); }, 2000); // print in console console.log("Hello"); https://github.com/sudar/jsfoo/blob/master/callback.js
Using Node.JS Install Node.JS Install NPM Install other modules you want by doing npm install <module_name> You are good to go
Node.JS – as an interactive shell Similar to Python’s shell $> node > 3 + 1 4 > true != false true >.help >.exit
Node.JS – As a server var http = require('http'); // require the http module // create a server http.createServer(function (req, res) {     // call this function when a request is received     res.writeHead(200, {         'Content-Type': 'text/plain'     });     // send this as part of the response res.end('Hello World'); }).listen(1337, "127.0.0.1"); // listen on port 1337 // debug information console.log('Server running at http://127.0.0.1:1337/'); https://github.com/sudar/jsfoo/blob/master/http-server.js
Node.JS – As a client var http = require('http'); // require the needed modules // make the request object var request = http.request({     'host': 'sudarmuthu.com',     'port': 80,     'path': '/',     'method': 'GET' }); // assign callbacks request.on('response', function (response) { console.log('Response Status Code: ' + response.statusCode); response.on('data', function (data) { console.log('Body: ' + data);     }); }); https://github.com/sudar/jsfoo/blob/master/http-client.js
Core Modules Processes Filesystem Networking Utilities The entire list can be found at http://nodejs.org/docs/v0.4.12/api/
Core Modules - Processes Node allows you to analyze your process and manage external process Available Modules process child_process Code samples:  http://github.com/sudar/jsfoo/process.js
Core Modules - Filesystem Low level API to manipulate files Available Modules fs path Code Samples: http://github.com/sudar/jsfoo/filesystem.js
Core Modules - Networking Available Modules net dgram http tls https dns Code Samples: https://github.com/sudar/jsfoo/blob/master/dns.js
Core Modules - Utilities Provides utility methods Available Modules console util Code Samples: https://github.com/sudar/jsfoo/blob/master/console.js
Node.JS is useful for.. Writing highly concurrent server applications Sharing application logic between server and client Peer-to-peer web applications using websockets
Terminologies NPM – Package manager (like apt-get) Modules – Plugins or add-ons for Node.JS Express – MVC framework (like RoR) Jade – Template Engine (like Smarty) Socket.IO – A websockets Library
Links http://github.com/sudar/jsfoo (all code samples used in this talk) http://nodejs.org http://npmjs.org http://expressjs.com http://socket.io
Questions Thank you Sudar Muthu http://sudarmuthu.com http://github.com/sudar http://twitter.com/sudarmuthu

More Related Content

What's hot

Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1
Mohammad Qureshi
 
Java script at backend nodejs
Java script at backend   nodejsJava script at backend   nodejs
Java script at backend nodejs
Amit Thakkar
 

What's hot (20)

3 Things Everyone Knows About Node JS That You Don't
3 Things Everyone Knows About Node JS That You Don't3 Things Everyone Knows About Node JS That You Don't
3 Things Everyone Knows About Node JS That You Don't
 
NodeJS ecosystem
NodeJS ecosystemNodeJS ecosystem
NodeJS ecosystem
 
Best node js course
Best node js courseBest node js course
Best node js course
 
Complete MVC on NodeJS
Complete MVC on NodeJSComplete MVC on NodeJS
Complete MVC on NodeJS
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDD
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS
 
Node js
Node jsNode js
Node js
 
Use Node.js to create a REST API
Use Node.js to create a REST APIUse Node.js to create a REST API
Use Node.js to create a REST API
 
Create Rest API in Nodejs
Create Rest API in Nodejs Create Rest API in Nodejs
Create Rest API in Nodejs
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1
 
RESTful API In Node Js using Express
RESTful API In Node Js using Express RESTful API In Node Js using Express
RESTful API In Node Js using Express
 
Nodejs getting started
Nodejs getting startedNodejs getting started
Nodejs getting started
 
Java script at backend nodejs
Java script at backend   nodejsJava script at backend   nodejs
Java script at backend nodejs
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...
Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...
Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...
 
Nodejs presentation
Nodejs presentationNodejs presentation
Nodejs presentation
 
Nodejs server lesson 3
 Nodejs server lesson 3 Nodejs server lesson 3
Nodejs server lesson 3
 
Node ppt
Node pptNode ppt
Node ppt
 
Non-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsNon-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.js
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 

Similar to A slightly advanced introduction to node.js

Node js presentation
Node js presentationNode js presentation
Node js presentation
martincabrera
 
The future of server side JavaScript
The future of server side JavaScriptThe future of server side JavaScript
The future of server side JavaScript
Oleg Podsechin
 
An Overview of Node.js
An Overview of Node.jsAn Overview of Node.js
An Overview of Node.js
Ayush Mishra
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Richard Lee
 

Similar to A slightly advanced introduction to node.js (20)

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
 
Node js presentation
Node js presentationNode js presentation
Node js presentation
 
The future of server side JavaScript
The future of server side JavaScriptThe future of server side JavaScript
The future of server side JavaScript
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSockets
 
Node.js Workshop - Sela SDP 2015
Node.js Workshop  - Sela SDP 2015Node.js Workshop  - Sela SDP 2015
Node.js Workshop - Sela SDP 2015
 
5.node js
5.node js5.node js
5.node js
 
Play! Framework for JavaEE Developers
Play! Framework for JavaEE DevelopersPlay! Framework for JavaEE Developers
Play! Framework for JavaEE Developers
 
hacking with node.JS
hacking with node.JShacking with node.JS
hacking with node.JS
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
 
Node.js - The New, New Hotness
Node.js - The New, New HotnessNode.js - The New, New Hotness
Node.js - The New, New Hotness
 
An Overview of Node.js
An Overview of Node.jsAn Overview of Node.js
An Overview of Node.js
 
node.js - Fast event based web application development
node.js - Fast event based web application developmentnode.js - Fast event based web application development
node.js - Fast event based web application development
 
Using and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareUsing and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middleware
 
Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.
 
Node.js: The What, The How and The When
Node.js: The What, The How and The WhenNode.js: The What, The How and The When
Node.js: The What, The How and The When
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Node.js: CAMTA Presentation
Node.js: CAMTA PresentationNode.js: CAMTA Presentation
Node.js: CAMTA Presentation
 
Original slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talk
 
Introduction to node.js
Introduction to  node.jsIntroduction to  node.js
Introduction to node.js
 
Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredev
 

More from Sudar Muthu

Capabilities of Arduino (including Due)
Capabilities of Arduino (including Due)Capabilities of Arduino (including Due)
Capabilities of Arduino (including Due)
Sudar Muthu
 

More from Sudar Muthu (20)

A quick preview of WP CLI - Chennai WordPress Meetup
A quick preview of WP CLI - Chennai WordPress MeetupA quick preview of WP CLI - Chennai WordPress Meetup
A quick preview of WP CLI - Chennai WordPress Meetup
 
WordPress Developer tools
WordPress Developer toolsWordPress Developer tools
WordPress Developer tools
 
WordPress Developer Tools to increase productivity
WordPress Developer Tools to increase productivityWordPress Developer Tools to increase productivity
WordPress Developer Tools to increase productivity
 
Unit testing for WordPress
Unit testing for WordPressUnit testing for WordPress
Unit testing for WordPress
 
Unit testing in php
Unit testing in phpUnit testing in php
Unit testing in php
 
Using arduino and raspberry pi for internet of things
Using arduino and raspberry pi for internet of thingsUsing arduino and raspberry pi for internet of things
Using arduino and raspberry pi for internet of things
 
How arduino helped me in life
How arduino helped me in lifeHow arduino helped me in life
How arduino helped me in life
 
Having fun with hardware
Having fun with hardwareHaving fun with hardware
Having fun with hardware
 
Getting started with arduino workshop
Getting started with arduino workshopGetting started with arduino workshop
Getting started with arduino workshop
 
Python in raspberry pi
Python in raspberry piPython in raspberry pi
Python in raspberry pi
 
Hack 101 at IIT Kanpur
Hack 101 at IIT KanpurHack 101 at IIT Kanpur
Hack 101 at IIT Kanpur
 
PureCSS open hack 2013
PureCSS open hack 2013PureCSS open hack 2013
PureCSS open hack 2013
 
Pig workshop
Pig workshopPig workshop
Pig workshop
 
Arduino Robotics workshop day2
Arduino Robotics workshop day2Arduino Robotics workshop day2
Arduino Robotics workshop day2
 
Arduino Robotics workshop Day1
Arduino Robotics workshop Day1Arduino Robotics workshop Day1
Arduino Robotics workshop Day1
 
Hands on Hadoop and pig
Hands on Hadoop and pigHands on Hadoop and pig
Hands on Hadoop and pig
 
Lets make robots
Lets make robotsLets make robots
Lets make robots
 
Capabilities of Arduino (including Due)
Capabilities of Arduino (including Due)Capabilities of Arduino (including Due)
Capabilities of Arduino (including Due)
 
Controlling robots using javascript
Controlling robots using javascriptControlling robots using javascript
Controlling robots using javascript
 
Picture perfect hacks with flickr API
Picture perfect hacks with flickr APIPicture perfect hacks with flickr API
Picture perfect hacks with flickr API
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Recently uploaded (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

A slightly advanced introduction to node.js

  • 1. An Introduction to Node.JS Sudar Muthu (@sudarmuthu) Research Engineer Yahoo Labs http://sudarmuthu.com
  • 2. Agenda What Node.JS is What Node.JS is not Why Node.JS? Using Node.JS As a interactive shell As a Server As a Client Common Modules Terminologies Questions
  • 3. What is Node.JS Provides Evented, non-blocking I/O Built on Google’s V8 JavaScript Programming Environment Supports C/C++ based addons Supports CommonJS Module format Is fast .. infact very fast.
  • 4. What is Node.JS Similar to EventMachine in Ruby Twisted in Python But provides Evented IO as part of the language construct itself and not as a library.
  • 5. Node.JS is not … Ruby on Rails Django Codeigniter Node.JS is bare bone and the community are making stuff like Express, connect etc.
  • 6. Why Node.JS? Code like this var result = db.query("select.."); // use result either blocks the entire process or implies multiple execution stacks (threads).
  • 7. Why Node.JS? But a line of code like this db.query("select..", function (result) { // use result }); allows the program to return to the event loop immediately. No more unnecessary threads.
  • 8. Demo of Callback // execute the callback after 2 seconds setTimeout(function () { console.log("World!"); }, 2000); // print in console console.log("Hello"); https://github.com/sudar/jsfoo/blob/master/callback.js
  • 9. Using Node.JS Install Node.JS Install NPM Install other modules you want by doing npm install <module_name> You are good to go
  • 10. Node.JS – as an interactive shell Similar to Python’s shell $> node > 3 + 1 4 > true != false true >.help >.exit
  • 11. Node.JS – As a server var http = require('http'); // require the http module // create a server http.createServer(function (req, res) { // call this function when a request is received res.writeHead(200, { 'Content-Type': 'text/plain' }); // send this as part of the response res.end('Hello World'); }).listen(1337, "127.0.0.1"); // listen on port 1337 // debug information console.log('Server running at http://127.0.0.1:1337/'); https://github.com/sudar/jsfoo/blob/master/http-server.js
  • 12. Node.JS – As a client var http = require('http'); // require the needed modules // make the request object var request = http.request({ 'host': 'sudarmuthu.com', 'port': 80, 'path': '/', 'method': 'GET' }); // assign callbacks request.on('response', function (response) { console.log('Response Status Code: ' + response.statusCode); response.on('data', function (data) { console.log('Body: ' + data); }); }); https://github.com/sudar/jsfoo/blob/master/http-client.js
  • 13. Core Modules Processes Filesystem Networking Utilities The entire list can be found at http://nodejs.org/docs/v0.4.12/api/
  • 14. Core Modules - Processes Node allows you to analyze your process and manage external process Available Modules process child_process Code samples: http://github.com/sudar/jsfoo/process.js
  • 15. Core Modules - Filesystem Low level API to manipulate files Available Modules fs path Code Samples: http://github.com/sudar/jsfoo/filesystem.js
  • 16. Core Modules - Networking Available Modules net dgram http tls https dns Code Samples: https://github.com/sudar/jsfoo/blob/master/dns.js
  • 17. Core Modules - Utilities Provides utility methods Available Modules console util Code Samples: https://github.com/sudar/jsfoo/blob/master/console.js
  • 18. Node.JS is useful for.. Writing highly concurrent server applications Sharing application logic between server and client Peer-to-peer web applications using websockets
  • 19. Terminologies NPM – Package manager (like apt-get) Modules – Plugins or add-ons for Node.JS Express – MVC framework (like RoR) Jade – Template Engine (like Smarty) Socket.IO – A websockets Library
  • 20. Links http://github.com/sudar/jsfoo (all code samples used in this talk) http://nodejs.org http://npmjs.org http://expressjs.com http://socket.io
  • 21. Questions Thank you Sudar Muthu http://sudarmuthu.com http://github.com/sudar http://twitter.com/sudarmuthu