An Overview of Node.js
Upcoming SlideShare
Loading in...5
×
 

An Overview of Node.js

on

  • 1,732 views

 

Statistics

Views

Total Views
1,732
Views on SlideShare
636
Embed Views
1,096

Actions

Likes
1
Downloads
13
Comments
0

6 Embeds 1,096

http://blog.knoldus.com 1083
http://feedly.com 9
http://knoldus.wordpress.com 1
http://digg.com 1
http://wordpress.com 1
http://www.inoreader.com 1

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • If you want to create more serious frontend stuff or you want to add more feature in your web page, we use jquery and prototype like this, whenever we felt like spicing up web page <br /> But this is still frontend stuff. Here you are just a javascript user, javascript developer. <br /> That&apos;s why node.js is created, javascript on the server. <br /> Node uses V8 , the virtual machine that powers Google Chrome, for server-side pro- <br /> gramming <br /> IT is build on google chrome runtime. It uses v8, the same run time environment, that google chrome uses. <br /> Actually reason is. Javasript is one context, which lives in browser. It defines only what you can do with the language. It does not say much about what lanuage itself can do. Node.js is anothe context. It allows you to run javascript as backend code outside a browser.In order to execute, javascript, that you intend to run in backend, it needs to be well interpreted and well execute , this is what node.js does with the use of v8 virtual macine. <br /> V8 gives a huge boost performance and it is developed by google. Because it prefers straight compilation into native machine code. And The compiled code is additionally optimized (and re-optimized) dynamically at runtime . <br />
  • npm is the official package manager for Node.js. As of Node.js version 0.6.3, npm is bundled and installed automatically with the environment.[1] npm runs through the command line and manages dependencies for an application. It also allows users to install Node.js applications that are available on the npm registry. <br /> npm is written entirely in JavaScript, and runs on the Node.js platform. <br /> The Node Package Manager (npm; https://github.com/isaacs/npm) is a util- <br /> ity that comes bundled with Node. It offers a great deal of functionality, allowing you <br /> to easily install third-party Node modules and globally publish any Node modules <br />
  • Node.js contains a built-in HTTP server library:-making it possible to run a web server without the use of external software, such asApache  <br /> You can use use https server by requiring http module. http module ships with node.js and <br />
  • Asynchronous and evented: the browser:- <br /> Node provides an event-driven and asynchronous platform for server-side JavaScript. <br /> It brings JavaScript to the server in much the same way a browser brings JavaScript to <br /> the client. Node.js is evet driven and non-blocking while handling i/o operation. <br /> event driven programming means where flow of program is detrmined by events such as mouse click, key press <br /> As we know Synchronous mode, the thread waits for I/O to complete before proceeding further. The thread will be in a “wait” state. <br /> However in the case of asynchronous operation, the thread will not wait for I/O to finish. It will continue with the processing till it gets interrupted <br /> Since node.js runs in a single thread, so you should use asychronus style of coading. <br />
  • Here you can see operation does not block execution. <br /> Here atually what is happening. Response from reourese.json would be stored in data. After that console.log function will execute. It will not execute untill it is ready. <br /> Browser is single threaded. If this request took 2 mins or 3 mins, any other event happening would have to wait for completion of this request. You can image a poor user experince, animation can be paused. <br /> Thankfully it will not happen in case of node.js. When any operation happens in the browser, it will happen out side of the event loop and then event is emitted when this operation is finished. This is called call back function. <br /> This will happen asynchronusly. It will not bloack the script execution. It will allow browser to be responsive to client and handle a lot of interactivity on the page <br />
  • it&apos;s just an example. The first line queries a database for lots of rows, the second line puts &quot;Hello World&quot; to the console. <br /> Let&apos;s assume that the database query is really slow, that it has to read an awful lot of rows, which takes several seconds. <br /> The way we have written this code, the JavaScript interpreter of Node.js first has to read the complete result set from the database, and then it can execute the console.log()function. <br /> The execution model of Node.js is different - there is only one single process. If there is a slow database query somewhere in this process, this affects the whole process - everything comes to a halt until the slow query has finished. <br /> We can understand this concept by analyzing a rewritten version of our problematic code: <br />

An Overview of Node.js An Overview of Node.js Presentation Transcript

  • Node.JsNode.Js Ayush Mishra Knoldus Software LLP Ayush Mishra Knoldus Software LLP
  • Topics CoveredTopics Covered 1. What is Node.js 2. Features Of Node.js 3. Testing Node Installation 4. Create HTTP server 5. URL Module 5. Event-Driven and Asynchronous Platform 6. Demo Application 1. What is Node.js 2. Features Of Node.js 3. Testing Node Installation 4. Create HTTP server 5. URL Module 5. Event-Driven and Asynchronous Platform 6. Demo Application
  • What is Node.jsWhat is Node.js Created by Ryan Dahl strating in 2009. Javascript on the server. A software platform that is used for easily building fast, scalable network applications (especially server-side) applications. Built on Google V8's Engine. Not executed in a web browser. Executed as a server-side JavaScript application. Created by Ryan Dahl strating in 2009. Javascript on the server. A software platform that is used for easily building fast, scalable network applications (especially server-side) applications. Built on Google V8's Engine. Not executed in a web browser. Executed as a server-side JavaScript application.
  • Developers can write web applications in one language. Uses event-driven, non-blocking I/O model for building scalable network application. Node.js ships with a lot of useful modules. Thus, Node.js is really two things: a runtime environment and a library. Uses npm (Node Package Manager) utility to install third party node modules. Node.js contains a built-in HTTP server library:-making it possible to run a web server without the use of external software, such as Apache and allowing more control of how the web server works. Developers can write web applications in one language. Uses event-driven, non-blocking I/O model for building scalable network application. Node.js ships with a lot of useful modules. Thus, Node.js is really two things: a runtime environment and a library. Uses npm (Node Package Manager) utility to install third party node modules. Node.js contains a built-in HTTP server library:-making it possible to run a web server without the use of external software, such as Apache and allowing more control of how the web server works. FeaturesFeatures
  • Testing Node InstallationTesting Node Installation 1)Create a file 'hello.js' 2) console.log(“Hello Knoldus”) 1)Create a file 'hello.js' 2) console.log(“Hello Knoldus”)
  • HTTP ServerHTTP Server
  • http.createServer([requestListener]) server.listen(port, [hostname], [callback]) server.listen(path, [callback]) server.close() http.createServer([requestListener]) server.listen(port, [hostname], [callback]) server.listen(path, [callback]) server.close() HTTP ServerHTTP Server
  • var http = require('http'); var content = '<html><body><p>Hello World</p><script type=”text/javascript”' +'>alert(“Hi!”);</script></body></html>'; http.createServer(function (request, response) { if (request.url === '/') { response.end(content); }else if (request.url === '/login') { response.end('Welcome To Login Page'); }else{ response.end('Wrong URL'); } }).listen(8080, 'localhost'); console.log('Server running at http://localhost:8080/.'); var http = require('http'); var content = '<html><body><p>Hello World</p><script type=”text/javascript”' +'>alert(“Hi!”);</script></body></html>'; http.createServer(function (request, response) { if (request.url === '/') { response.end(content); }else if (request.url === '/login') { response.end('Welcome To Login Page'); }else{ response.end('Wrong URL'); } }).listen(8080, 'localhost'); console.log('Server running at http://localhost:8080/.');
  •  Call require('url') to use it.  url.parse(urlStr, parseQueryString = false): Parses a URL string and returns an object which contains the various parts of the URL.  url.format(urlObj): Accepts a parsed URL object and returns the string. Does the reverse of url.parse().  url.resolve(from, to): Resolves a given URL relative to a base URL as a browser would for an anchor tag.  Call require('url') to use it.  url.parse(urlStr, parseQueryString = false): Parses a URL string and returns an object which contains the various parts of the URL.  url.format(urlObj): Accepts a parsed URL object and returns the string. Does the reverse of url.parse().  url.resolve(from, to): Resolves a given URL relative to a base URL as a browser would for an anchor tag. URLURL
  • URLURL
  • Event-Driven and Asynchronous PlatformEvent-Driven and Asynchronous Platform
  • $.post('/resource.json', function (data) { // I/O doesn’t block execution console.log(data); }); Console.log(“hello”) var data = $.post('/resource.json');//I/O blocks execution console.log(data); Console.log(“hello”) $.post('/resource.json', function (data) { // I/O doesn’t block execution console.log(data); }); Console.log(“hello”) var data = $.post('/resource.json');//I/O blocks execution console.log(data); Console.log(“hello”)
  • 1) var result = database.query("SELECT * FROM employee"); console.log("Hello World"); 2) database.query("SELECT * FROM employee", function(rows) { var result = rows; }); console.log("Hello World"); 3)var http = require("http"); 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(8888); console.log("Server has started."); 1) var result = database.query("SELECT * FROM employee"); console.log("Hello World"); 2) database.query("SELECT * FROM employee", function(rows) { var result = rows; }); console.log("Hello World"); 3)var http = require("http"); 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(8888); console.log("Server has started.");
  • Login ApplicationLogin Application https://github.com/knoldus/Node.js_UserLogin_Templatehttps://github.com/knoldus/Node.js_UserLogin_Template
  • ThanksThanks