Node.js

2,039 views

Published on

->It´s web server is able to handle a HUGE number of connections out of the box
->Various libraries can be run on browser, the same as in the server
->Very friendly to Websockets (real-time web apps)
->Lots of libraries are being ported to it from other langs.
->Express, inspired in ruby´s Sinatra; is very light on memory but also very powerful

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

No Downloads
Views
Total views
2,039
On SlideShare
0
From Embeds
0
Number of Embeds
38
Actions
Shares
0
Downloads
15
Comments
2
Likes
0
Embeds 0
No embeds

No notes for slide

Node.js

  1. 1. node.js Hello WorldNode.js – Web Framework By:Pravin Mishra pravinmisrha88@gmail.com
  2. 2. Contents• Why Node.js?• Node Overview• Benefits of Node.js• Create Server Request.• Write HTTP Header.• listen for new requests .• print out a message.• Run program.• Questions?
  3. 3. Why Node.js?->Nodes goal is to provide an easyway to build scalable networkPrograms.->Keep slow operations fromblocking other operations.
  4. 4. What is Node.js?->Standard library.Timers, Process, Events, Util, Buffer,Crypto, TLS/SSL, FileSystem, Net, DNS,HTTP/HTTPS, URL, UDP.-> I/O needs to be done differently
  5. 5. Templating• Jade.• EJS.• Haml.• Sass
  6. 6. Database• Mysql• Redis• MongoDB• CouchBD
  7. 7. Deploy• Heroku• Nodejitsu• Cluster
  8. 8. Benefits of Node.js- No need to wait for the disk,do something else meanwhile! - Keep slow operations fromblocking other operations. - To read info from disk, network, ... there must be acallback-Asynchronous event-driven model
  9. 9. Create Server Rquestvar http = require("http");http.createServer(function (request, response){ response.end("<h2>This is the end!</h2>");}).listen(3000, “127.0.0.1″);->The require function will return an object representing the module that youpass into it and you can capture that object in a variable.->The createServer that takes a callback function and returns a new serverobject.
  10. 10. Write HTTP headers.var http = require("http");http.createServer(function (request, response){ res.writeHead(200, {‘content-Type’:text/html’}); response.end("<h2>This is the end!</h2>");}).listen(3000, “127.0.0.1″);->Then first need to write the appropriate HTTP headers.->The writeHead function takes a couple of arguments. The first is an integer value representing the status code of the request which for us will be 200, in other words
  11. 11. write functionvar http = require("http");http.createServer(function (request, response){ res.writeHead(200, {‘content-Type’:text/html’}); res.write(“<h1>Hello Word!</h1>”) response.end("<h2>This is the end!</h2>");}).listen(3000, “127.0.0.1″);->Then we’ll call the write function and pass in the data that you wish to send.
  12. 12. listen for new requestsvar http = require("http");http.createServer(function (request, response){ res.writeHead(200, {‘content-Type’:text/html’}); res.write(“<h1>Hello Word!</h1>”) response.end("<h2>This is the end!</h2>");}).listen(3000, “127.0.0.1″);->The listen function on our server object and pass in a port number for it to listen on(3000). The listen function also takes an optional second parameter which is the hostname URL(“127.0.0.1″),
  13. 13. print out a messagevar http = require("http");http.createServer(function (request, response){ res.writeHead(200, {‘content-Type’:text/html’}); res.write(“<h1>Hello Word!</h1>”) response.end("<h2>This is the end!</h2>");}).listen(3000, “127.0.0.1″);console.log(“Listening on http://127.0.0.1:3000“).->Finally, let’s print out a message to let us know that our server is running
  14. 14. Run ProgramThere we go, now let’s run our app by calling node and passing to it the name of the file we want it to execute.node hello_world.js and open browser “http://127.0.0.1:3000“That’s it. Enjoy………………..
  15. 15. THANKS Questions? By:Pravin Mishra Rails/UI Developerpravinmishra88@gmail.com

×