Your SlideShare is downloading. ×
0
Node JS
Node JS
Node JS
Node JS
Node JS
Node JS
Node JS
Node JS
Node JS
Node JS
Node JS
Node JS
Node JS
Node JS
Node JS
Node JS
Node JS
Node JS
Node JS
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

Node JS

1,541

Published on

Kushal tries to demystify Node.js, a server side javascripting tool through this set of slides.

Kushal tries to demystify Node.js, a server side javascripting tool through this set of slides.

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

No Downloads
Views
Total Views
1,541
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
29
Comments
0
Likes
2
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. . Node.js By Kushal Likhi
  • 2. Overview → Install Node.js → Node prompt / ”Hello World” Program → Creating/Analyzing our first basic HTTP server → How server handles requests ? → How to route request ? → Benchmark Performance → Javascript Adoptability → Node package manager → Frameworks
  • 3. Node.js has the potential to revolutionize web development.It is a framework for building high performance webapplications.Applications that can respond very quickly and efficiently to ahigh volume of incoming requests.
  • 4. Install Node.jsClick on the link for downloading node js package forwindows,mac,linux etc .http://nodejs.org/download/
  • 5. Node PromptType node on command line.Try executing JavaScript / Node.js code there.
  • 6. ”Hello World” Program (helloWorld.js)We will Write the "Hello World" to STDOUT.1. Open any editor and create a file called helloworld.js.2. Write below code to file and save it. console.log("Hello World");3. To excute the file run below command. node helloworld.js
  • 7. Our first HTTP server (firstServer.js)1. We will use HTTP Module to create our first basic server. var http = require("http"); var helloWorldAction = function(request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello World"); response.end(); }; var server = http.createServer(helloWorldAction ); server.listen(9999);
  • 8. Our first basic HTTP server ...2. Execute your script: node firstServer.js3. Open your browser and hit below URL: http://localhost:9999/
  • 9. Analyzing our HTTP server1. The first line requires the http module that ships with Node.js and makes it accessible through the variable http.2. We then call one of the functions the http module offers: createServer, which returns an object and we store that object in variable server.3. This object has a method named listen, and takes a numeric value which indicates the port number our HTTP server is going to listen on. That listen method would start an HTTP server listening at port 8888
  • 10. How server handles requests:Whenever a request received, helloWorldAction function getstriggered and two parameters are passed into it: request andresponse.1. response.writeHead() send an HTTP status and content-type in the HTTP response header.2. response.write() send the text in the HTTP response body.3. response.end() finish response.
  • 11. How to route requests??→ We get the URL from request→ We transfer the request to the desired handler based on the URL mappings we have.→ There are frameworks which does that for us.
  • 12. Benchmark Node.jsApache HTTP server benchmarking tool can be used forbenchmarking .For ex : sending 10,000 Requests with 1000 requestcuncurrentlyab -n 10000 -c 1000 http://localhost:9999/For details of command ab visit :http://httpd.apache.org/docs/2.2/programs/ab.htm l
  • 13. Where lies the Power?Power lies in the Unblocking Asynchronous model of JavaScript. → CPU is best utilized. → Always a room for new request.
  • 14. JavaScript Adoptability→ GNOME3 Desktop in JavaScrpt→ Windows 8 UI in JavaScript→ Windows 8 app development in JavaScript http://msdn.microsoft.com/en-in/library/windows/apps/br211385.aspx→ Servers Shifting to JavaScript→ Hundreds of frameworks are being developed→ Node.js Supported by almost all providers including heruku, appfog, Azure, VMware etc.→ JavaScript is rated as first class serious language and is used in Neural Network and Artificial intelligence implementations.→ Databases like mongoDB uses JavaScript
  • 15. Node Package ManagerThere are pluging for Node js. We can install them simply via npm command.Demo:→NPM Site - https://npmjs.org/→ MailsExample:→ SQL ORM Plugin https://github.com/objectundefined/OurSqlhttp://sequelizejs.com/→ Pusher plugin→ Mail Plugin https://github.com/andris9/Nodemailerhttps://github.com/niftylettuce/node-email-templatesetc...
  • 16. FrameworksThere are lots of frameworks for Node.js. →Express →Geddy →Connect →RailwayJSExpress is one of the popular one.Lets try it out!!
  • 17. Express→ mkdir projectDir→ npm install express→ express –sessions -J→ npm install→ node app
  • 18. Referenceshttp://www.nodebeginner.org/http://howtonode.org/http://nodetuts.com/
  • 19. Thank You

×