Your SlideShare is downloading. ×
Introduction to Node.js Platform
Introduction to Node.js Platform
Introduction to Node.js Platform
Introduction to Node.js Platform
Introduction to Node.js Platform
Introduction to Node.js Platform
Introduction to Node.js Platform
Introduction to Node.js Platform
Introduction to Node.js Platform
Introduction to Node.js Platform
Introduction to Node.js Platform
Introduction to Node.js Platform
Introduction to Node.js Platform
Introduction to Node.js Platform
Introduction to Node.js Platform
Introduction to Node.js Platform
Introduction to Node.js Platform
Introduction to Node.js Platform
Introduction to Node.js Platform
Introduction to Node.js Platform
Introduction to Node.js Platform
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Introduction to Node.js Platform

1,142

Published on

Introduction to Node.js & JavaScript Platform

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,142
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
3
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 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
  • 9. NODE.JS Understanding Node.js Code
  • 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(); } );
  • 21. THANK YOU Thank You

×