SlideShare a Scribd company logo
1 of 21
INTRODUCTION TO NODE.JS
SERVER-SIDE JAVASCRIPT & EVENT-DRIVEN PLATFORM

Naresh Chintalcheru
NODE.JS


Node.js is a platform to build fast, scalable and
high-throughput network applications



Uses single-threaded Event-Loop & NonBlocking I/O model that makes it lightweight and
efficient use of Server resources



JavaScript Runtime on the Server



Browser based IDE’s



No multi-thread locking burden on the runtime
JAVASCRIPT


JavaScript is an object-oriented and
functional style scripting language



Runs on a single-threaded runtime



Dynamic Typing and Prototype-based
var person1 = new Person(‘John’, ‘Smith’);
Type-of-Variable Vs Type-of-Value
JAVASCRIPT


Dynamic Typing and Prototype-based language
var person1 = new Person(‘John’, ‘Smith’);



No Person class but a Person Prototype
var Person = function() {
this.fname = "";
this.lname = "";
this.greet = function() {
console.log("Hi, I'm " + this.fname);
};
};
JAVASCRIPT INHERITANCE
var Person = function() {
this.fname = "";
this.lname = "";
};
var Employee = function() {
this.title = "";
this.salary = "";
};
Employee.prototype = new Person();
JAVASCRIPT FUNCTIONS


Functions are the first-class citizens



Pass around Closure functions makes EventDriven programming simple



Closures
 Pass

functions to the method parameters
 Method returns data or functions
SERVER-SIDE VS CLIENT-SIDE


JavaScript is born and live in the client-side
browsers



Has ability to run on the server-side



Server-side JavaScript will not have the
browser based global objects such as
Window & Document but does have objects
http/url etc provided by the Node.js platform
JAVASCRIPT RUNTIME


Node.js uses the Googles V8 JavaScript
Engine used in chrome browser



V8 Runtime Engine uses Heap memory for
JavaScript objects & functions



V8 has Garbage Collection for memory
management



V8 JIT (Just-In-Time) Compiler
NODE.JS

Understanding Node.js Code
NODE.JS

Node.js is Platform + Runtime

No need of a Web Server
NODE.JS SERVER
var http = require("http");
Callback function

function onRequest(request, response) {
console.log("Request received.");

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

}

response.write("Hello World");
response.end();

http.createServer(onRequest).listen(8080);
console.log("Server has started.")
NODE.JS

Routes & Request Handlers are
Controllers/Models in MVC
NODE.JS SERVER
var http = require("http");
function onRequest(request, response) {
var pathname = url.parse(request.url).pathname;
route(pathname);
response.writeHead(200, {"Content-Type": "text/plain"});

}

response.end();

http.createServer(onRequest).listen(8080);
console.log("Server has started.")
Route Handles /AddEmp /SearchEmp
EXPRESS.JS

Express.js MVC framework for Node.js

(Similar to Struts, JSF & SpringMVC for JEE)
EXPRESS.JS

Express.js MVC Framework handles Routes,
Request Handlers and Views for Node.js
EXPRESS.JS
//start Express
var express = require("express");
var app = express();
//set the view directory to /views
app.set("views", __dirname + "/views");
app.set("view engine", "jade");
//Delete an Employee; Routes And Request Handlers

app.post('/employee/delete:id/', function(req, res) {
employeeProvider.delete(req.param('_id'),
function(error, docs) {res.redirect('/')}) ;});
EXPRESS.JS
//start Express
var express = require("express");
var app = express();
var routes = require('./routes');

Struts-config.xml

//set the view directory to /views
app.set("views", __dirname + "/views");
app.set("view engine", "jade");
app.get('/emplist', routes.emplist(db));
app.get('/addemp', routes.addemp);
EXPRESS.JS & SPRING MVC
//Express delete an Employee
app.post('/employee/delete:id/', function(req, res) {
employeeProvider.delete(req.param('_id'),
function(error, docs) {res.redirect('/')});
});
//Spring MVC delete an Employee
@Controller
public class SpringMVCController {
@RequestMapping(value = "/employee/delete", method = RequestMethod.GET)
public String delete(@RequestParam("id") String name, Model model) {

employeeDAO.delete(id);
return “deleteSuccess";
}
DATA PERSISTENCE

Node.js can access RDBMS and NoSQL
Databases
DATA PERSISTENCE
var mysql = require('mysql');
var conn = mysql.createConnection({ host :
“localhost:3700”, user : “uid”, password: “pwd” });

conn.getConnection(function(err, connection){
connection.query( “select * from table1”,
function(err, rows){ if(err) { throw err; }});

connection.release(); }
);
THANK YOU

Thank You

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
 
Introduction to nodejs
Introduction to nodejsIntroduction to nodejs
Introduction to nodejs
James Carr
 

What's hot (20)

Node js for beginners
Node js for beginnersNode js for beginners
Node js for beginners
 
Building a real life application in node js
Building a real life application in node jsBuilding a real life application in node js
Building a real life application in node js
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1
 
Node js
Node jsNode js
Node js
 
Node.js Workshop - Sela SDP 2015
Node.js Workshop  - Sela SDP 2015Node.js Workshop  - Sela SDP 2015
Node.js Workshop - Sela SDP 2015
 
Cli jbug
Cli jbugCli jbug
Cli jbug
 
JAX-RS 2.1 Reloaded @ Devoxx
JAX-RS 2.1 Reloaded @ DevoxxJAX-RS 2.1 Reloaded @ Devoxx
JAX-RS 2.1 Reloaded @ Devoxx
 
Module design pattern i.e. express js
Module design pattern i.e. express jsModule design pattern i.e. express js
Module design pattern i.e. express js
 
Asynchronous Web Programming with HTML5 WebSockets and Java
Asynchronous Web Programming with HTML5 WebSockets and JavaAsynchronous Web Programming with HTML5 WebSockets and Java
Asynchronous Web Programming with HTML5 WebSockets and Java
 
Express node js
Express node jsExpress node js
Express node js
 
Jolokia - JMX on Capsaicin (Devoxx 2011)
Jolokia - JMX on Capsaicin (Devoxx 2011)Jolokia - JMX on Capsaicin (Devoxx 2011)
Jolokia - JMX on Capsaicin (Devoxx 2011)
 
Getting started with node JS
Getting started with node JSGetting started with node JS
Getting started with node JS
 
Realtime web application with java
Realtime web application with javaRealtime web application with java
Realtime web application with java
 
Introduction to node.js aka NodeJS
Introduction to node.js aka NodeJSIntroduction to node.js aka NodeJS
Introduction to node.js aka NodeJS
 
Express js
Express jsExpress js
Express js
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
 
Introduction to nodejs
Introduction to nodejsIntroduction to nodejs
Introduction to nodejs
 
Communication in Node.js
Communication in Node.jsCommunication in Node.js
Communication in Node.js
 
Node.js Express Framework
Node.js Express FrameworkNode.js Express Framework
Node.js Express Framework
 
Microservices in Scala: Play Framework
Microservices in Scala: Play FrameworkMicroservices in Scala: Play Framework
Microservices in Scala: Play Framework
 

Similar to Introduction to Node.js Platform

Node js introduction
Node js introductionNode js introduction
Node js introduction
Alex Su
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
Tom Croucher
 
Scalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JSScalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JS
Cosmin Mereuta
 

Similar to Introduction to Node.js Platform (20)

Event driven programming -- Node.JS
Event driven programming -- Node.JSEvent driven programming -- Node.JS
Event driven programming -- Node.JS
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Server Side Event Driven Programming
Server Side Event Driven ProgrammingServer Side Event Driven Programming
Server Side Event Driven Programming
 
NodeJS
NodeJSNodeJS
NodeJS
 
Meetup RomaJS - introduzione interattiva a Node.js - Luca Lanziani - Codemoti...
Meetup RomaJS - introduzione interattiva a Node.js - Luca Lanziani - Codemoti...Meetup RomaJS - introduzione interattiva a Node.js - Luca Lanziani - Codemoti...
Meetup RomaJS - introduzione interattiva a Node.js - Luca Lanziani - Codemoti...
 
Node.js 1, 2, 3
Node.js 1, 2, 3Node.js 1, 2, 3
Node.js 1, 2, 3
 
Node.js introduction
Node.js introductionNode.js introduction
Node.js introduction
 
Intro to Node
Intro to NodeIntro to Node
Intro to Node
 
Node js beginner
Node js beginnerNode js beginner
Node js beginner
 
Introduction to REST API with Node.js
Introduction to REST API with Node.jsIntroduction to REST API with Node.js
Introduction to REST API with Node.js
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 
Groovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentationGroovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentation
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
5.node js
5.node js5.node js
5.node js
 
Scalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JSScalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JS
 
Node.js
Node.jsNode.js
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 on Azure
Node.js on AzureNode.js on Azure
Node.js on Azure
 
Node JS reverse shell
Node JS reverse shellNode JS reverse shell
Node JS reverse shell
 
CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure
CloudConnect 2011 - Building Highly Scalable Java Applications on Windows AzureCloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure
CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure
 

More from Naresh Chintalcheru

More from Naresh Chintalcheru (15)

Cars.com Journey to AWS Cloud
Cars.com Journey to AWS CloudCars.com Journey to AWS Cloud
Cars.com Journey to AWS Cloud
 
Bimodal IT for Speed and Innovation
Bimodal IT for Speed and InnovationBimodal IT for Speed and Innovation
Bimodal IT for Speed and Innovation
 
Reactive systems
Reactive systemsReactive systems
Reactive systems
 
Asynchronous Processing in Java/JEE/Spring
Asynchronous Processing in Java/JEE/SpringAsynchronous Processing in Java/JEE/Spring
Asynchronous Processing in Java/JEE/Spring
 
Problems opening SOA to the Online Web Applications
Problems opening SOA to the Online Web ApplicationsProblems opening SOA to the Online Web Applications
Problems opening SOA to the Online Web Applications
 
Lie Cheat & Steal to build Hyper-Fast Applications using Event-Driven Archite...
Lie Cheat & Steal to build Hyper-Fast Applications using Event-Driven Archite...Lie Cheat & Steal to build Hyper-Fast Applications using Event-Driven Archite...
Lie Cheat & Steal to build Hyper-Fast Applications using Event-Driven Archite...
 
Java7 New Features and Code Examples
Java7 New Features and Code ExamplesJava7 New Features and Code Examples
Java7 New Features and Code Examples
 
Big Trends in Big Data
Big Trends in Big DataBig Trends in Big Data
Big Trends in Big Data
 
Design & Develop Batch Applications in Java/JEE
Design & Develop Batch Applications in Java/JEEDesign & Develop Batch Applications in Java/JEE
Design & Develop Batch Applications in Java/JEE
 
Building Next Generation Real-Time Web Applications using Websockets
Building Next Generation Real-Time Web Applications using WebsocketsBuilding Next Generation Real-Time Web Applications using Websockets
Building Next Generation Real-Time Web Applications using Websockets
 
Mule ESB Fundamentals
Mule ESB FundamentalsMule ESB Fundamentals
Mule ESB Fundamentals
 
Automation Testing using Selenium
Automation Testing using SeleniumAutomation Testing using Selenium
Automation Testing using Selenium
 
Design & Development of Web Applications using SpringMVC
Design & Development of Web Applications using SpringMVC Design & Development of Web Applications using SpringMVC
Design & Development of Web Applications using SpringMVC
 
Android Platform Architecture
Android Platform ArchitectureAndroid Platform Architecture
Android Platform Architecture
 
Object-Oriented Polymorphism Unleashed
Object-Oriented Polymorphism UnleashedObject-Oriented Polymorphism Unleashed
Object-Oriented Polymorphism Unleashed
 

Recently uploaded

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 

Introduction to Node.js Platform

  • 1. INTRODUCTION TO NODE.JS SERVER-SIDE JAVASCRIPT & EVENT-DRIVEN PLATFORM Naresh Chintalcheru
  • 2. NODE.JS  Node.js is a platform to build fast, scalable and high-throughput network applications  Uses single-threaded Event-Loop & NonBlocking I/O model that makes it lightweight and efficient use of Server resources  JavaScript Runtime on the Server  Browser based IDE’s  No multi-thread locking burden on the runtime
  • 3. JAVASCRIPT  JavaScript is an object-oriented and functional style scripting language  Runs on a single-threaded runtime  Dynamic Typing and Prototype-based var person1 = new Person(‘John’, ‘Smith’); Type-of-Variable Vs Type-of-Value
  • 4. JAVASCRIPT  Dynamic Typing and Prototype-based language var person1 = new Person(‘John’, ‘Smith’);  No Person class but a Person Prototype var Person = function() { this.fname = ""; this.lname = ""; this.greet = function() { console.log("Hi, I'm " + this.fname); }; };
  • 5. JAVASCRIPT INHERITANCE var Person = function() { this.fname = ""; this.lname = ""; }; var Employee = function() { this.title = ""; this.salary = ""; }; Employee.prototype = new Person();
  • 6. JAVASCRIPT FUNCTIONS  Functions are the first-class citizens  Pass around Closure functions makes EventDriven programming simple  Closures  Pass functions to the method parameters  Method returns data or functions
  • 7. SERVER-SIDE VS CLIENT-SIDE  JavaScript is born and live in the client-side browsers  Has ability to run on the server-side  Server-side JavaScript will not have the browser based global objects such as Window & Document but does have objects http/url etc provided by the Node.js platform
  • 8. JAVASCRIPT RUNTIME  Node.js uses the Googles V8 JavaScript Engine used in chrome browser  V8 Runtime Engine uses Heap memory for JavaScript objects & functions  V8 has Garbage Collection for memory management  V8 JIT (Just-In-Time) Compiler
  • 10. NODE.JS Node.js is Platform + Runtime No need of a Web Server
  • 11. NODE.JS SERVER var http = require("http"); Callback function function onRequest(request, response) { console.log("Request received."); response.writeHead(200, {"Content-Type": "text/plain"}); } response.write("Hello World"); response.end(); http.createServer(onRequest).listen(8080); console.log("Server has started.")
  • 12. NODE.JS Routes & Request Handlers are Controllers/Models in MVC
  • 13. NODE.JS SERVER var http = require("http"); function onRequest(request, response) { var pathname = url.parse(request.url).pathname; route(pathname); response.writeHead(200, {"Content-Type": "text/plain"}); } response.end(); http.createServer(onRequest).listen(8080); console.log("Server has started.") Route Handles /AddEmp /SearchEmp
  • 14. EXPRESS.JS Express.js MVC framework for Node.js (Similar to Struts, JSF & SpringMVC for JEE)
  • 15. EXPRESS.JS Express.js MVC Framework handles Routes, Request Handlers and Views for Node.js
  • 16. EXPRESS.JS //start Express var express = require("express"); var app = express(); //set the view directory to /views app.set("views", __dirname + "/views"); app.set("view engine", "jade"); //Delete an Employee; Routes And Request Handlers app.post('/employee/delete:id/', function(req, res) { employeeProvider.delete(req.param('_id'), function(error, docs) {res.redirect('/')}) ;});
  • 17. EXPRESS.JS //start Express var express = require("express"); var app = express(); var routes = require('./routes'); Struts-config.xml //set the view directory to /views app.set("views", __dirname + "/views"); app.set("view engine", "jade"); app.get('/emplist', routes.emplist(db)); app.get('/addemp', routes.addemp);
  • 18. EXPRESS.JS & SPRING MVC //Express delete an Employee app.post('/employee/delete:id/', function(req, res) { employeeProvider.delete(req.param('_id'), function(error, docs) {res.redirect('/')}); }); //Spring MVC delete an Employee @Controller public class SpringMVCController { @RequestMapping(value = "/employee/delete", method = RequestMethod.GET) public String delete(@RequestParam("id") String name, Model model) { employeeDAO.delete(id); return “deleteSuccess"; }
  • 19. DATA PERSISTENCE Node.js can access RDBMS and NoSQL Databases
  • 20. DATA PERSISTENCE var mysql = require('mysql'); var conn = mysql.createConnection({ host : “localhost:3700”, user : “uid”, password: “pwd” }); conn.getConnection(function(err, connection){ connection.query( “select * from table1”, function(err, rows){ if(err) { throw err; }}); connection.release(); } );