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...
JAVASCRIPT


JavaScript is an object-oriented and
functional style scripting language



Runs on a single-threaded runti...
JAVASCRIPT


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



No Person class b...
JAVASCRIPT INHERITANCE
var Person = function() {
this.fname = "";
this.lname = "";
};
var Employee = function() {
this.tit...
JAVASCRIPT FUNCTIONS


Functions are the first-class citizens



Pass around Closure functions makes EventDriven program...
SERVER-SIDE VS CLIENT-SIDE


JavaScript is born and live in the client-side
browsers



Has ability to run on the server...
JAVASCRIPT RUNTIME


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



V8 Runtime Engine uses Heap...
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...
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).p...
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.s...
EXPRESS.JS
//start Express
var express = require("express");
var app = express();
var routes = require('./routes');

Strut...
EXPRESS.JS & SPRING MVC
//Express delete an Employee
app.post('/employee/delete:id/', function(req, res) {
employeeProvide...
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”, ...
THANK YOU

Thank You
Upcoming SlideShare
Loading in...5
×

Introduction to Node.js Platform

1,255

Published on

Introduction to Node.js & JavaScript Platform

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,255
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Introduction to Node.js Platform

  1. 1. INTRODUCTION TO NODE.JS SERVER-SIDE JAVASCRIPT & EVENT-DRIVEN PLATFORM Naresh Chintalcheru
  2. 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. 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. 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. 5. JAVASCRIPT INHERITANCE var Person = function() { this.fname = ""; this.lname = ""; }; var Employee = function() { this.title = ""; this.salary = ""; }; Employee.prototype = new Person();
  6. 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. 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. 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
  9. 9. NODE.JS Understanding Node.js Code
  10. 10. NODE.JS Node.js is Platform + Runtime No need of a Web Server
  11. 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. 12. NODE.JS Routes & Request Handlers are Controllers/Models in MVC
  13. 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. 14. EXPRESS.JS Express.js MVC framework for Node.js (Similar to Struts, JSF & SpringMVC for JEE)
  15. 15. EXPRESS.JS Express.js MVC Framework handles Routes, Request Handlers and Views for Node.js
  16. 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. 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. 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. 19. DATA PERSISTENCE Node.js can access RDBMS and NoSQL Databases
  20. 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(); } );
  21. 21. THANK YOU Thank You

×