hacking with node.JS

8,985 views
8,614 views

Published on

Getting started with node.JS

Published in: Technology
1 Comment
5 Likes
Statistics
Notes
No Downloads
Views
Total views
8,985
On SlideShare
0
From Embeds
0
Number of Embeds
58
Actions
Shares
0
Downloads
82
Comments
1
Likes
5
Embeds 0
No embeds

No notes for slide
  • Demo hello-world.js and hello-world.phpThen hello-world-2.js Actually there isn't a lot new here. But then again, there was nothing new about node either. Node uses non-blocking IO for fast scalable servers. That's been known about for years among the C community. It uses event based, single thread javascript for logic. That's exactly what the browser has. Add these together and we all see the huge splash it's made. It's the unique combination of some simple but complimentary ideas that really make these projects zing.
  • Re – usability of code. Give example of YUIExecute JS based on device.
  • Hello-server.js
  • Show npm search, install,ls, uninstallShow search.npmjs.orgMath.js
  • hacking with node.JS

    1. 1.
    2. 2. #hacking withnode.JS<br />HarshaVashisht<br />http://www.harsharv.com<br />@harsharv<br />Picture Source: http://bethesignal.org/blog/2011/01/06/speaking-lca2011-html5-nodejs/<br />
    3. 3. What is node.js?<br />
    4. 4. Node is an exciting new platform developed byRyan Dahl.<br />
    5. 5. It is a lot of sugar on v8<br />
    6. 6. It allows JavaScript developers to create extremely high performance servers by leveraging Google's V8 JavaScript engine, and asynchronous I/O.<br />
    7. 7. Never wait it the motto<br />
    8. 8. Recap… What is Node.js?<br /><ul><li>Node is an exciting new platform developed by Ryan Dahl.
    9. 9. It allows JavaScript developers to create extremely high performance servers by leveraging Google's V8 JavaScript engine, and asynchronous I/O.
    10. 10. Node is a lot of Sugar written on V8
    11. 11. Never wait is the motto. Either to fetch a page from the web or fetch data from a DB.</li></li></ul><li>let us look at…<br />
    12. 12. DUCK! There will be code…<br />Lets see cod<br />
    13. 13. LAMP STACK<br />1. Order<br />2. Waits for the food<br />to be cooked<br />3.Food is ready<br />4. Serve<br />
    14. 14. Node JS<br />1. Order<br />2. Places the order<br />with the cook<br />3. Immediately moves on to take the order from the next table<br />4. Cook notifies that the food is <br />ready<br />5. Food is served<br />
    15. 15. commonjs<br />CommonJS is a community driven effort to standardize packaging of JavaScript libraries, known as modules. Modules written which comply to this standard provide portability between other compliant frameworks such as narwhal, and in some cases even browsers.*<br />* Conditions Apply<br />
    16. 16. Why node.js?<br />
    17. 17. Global objects<br /><ul><li>Require
    18. 18. Module/ export
    19. 19. Process</li></li></ul><li>Require<br />This is used to specify that a module is required.<br />Example:<br />var operation = require(“pow”)<br />
    20. 20. Module/ exports<br />This is used to package JavaScript libraries and expose the functionality to be used else where.<br />Example:<br />exports.pow = function (a, b) { <br /> …<br />}<br />
    21. 21. process<br /><ul><li>The process object is a global object and can be accessed from anywhere.
    22. 22. It is an instance of EventEmitter.
    23. 23. Can be thought as an equivalent to Window object in the browser</li></ul>Examples:<br /><ul><li>process.cwd()
    24. 24. process.exit(1)
    25. 25. process.argv
    26. 26. process.on('exit', function () { </li></ul> ...}<br /><ul><li>process.on('uncaughtException', function (err) {</li></ul> …}<br />
    27. 27. Simple http server<br />/* File Name: hello-server.js */<br />/* Include the http module. */<br />var http = require('http');<br />/* Create a server which accepts Request - req and returns Response - res */<br />http.createServer(function (req, res) {<br /> /* Set the HTTP header for the response. */<br /> res.writeHead(200, {'Content-Type': 'text/plain'});<br /> /* End the HTTP response */<br />res.end('Hello Worldn');<br />}).listen(9000, "127.0.0.1");<br />/* Print a message to indicate that the server is running. */<br />console.log('Server running at http://127.0.0.1:9000/');<br />
    28. 28. Modules lets right some<br />
    29. 29. Calculate power of a number<br />exports.pow = function (a, b) {<br /> /* Check if a number is passed. */<br /> if (isNaN (a-0) || isNaN (b-0)) {<br /> return null;<br /> }<br />varans = 1;<br />for (vari = 1; i <= b; i++) {<br />ans *= a;<br /> }<br /> return ans;<br />}<br />Link: https://github.com/harsharv/OpenHackDay2011/blob/master/hello-server.js<br />
    30. 30. twitter search module<br />https://github.com/harsharv/OpenHackDay2011/blob/master/twitter.js<br />https://github.com/harsharv/OpenHackDay2011/blob/master/mashup.js<br />
    31. 31. Npm – node package manager<br /><ul><li>npm is the package manager for the Node JavaScript platform
    32. 32. It puts modules in place so that node can find them, and manages dependency conflicts intelligently.</li></li></ul><li>More about npm<br /><ul><li>Install NPM</li></ul>curl http://npmjs.org/install.sh | sh<br /><ul><li>Browse the packages of NPMhttp://search.npmjs.org/</li></li></ul><li>Npm basic commands<br /><ul><li>npm search
    33. 33. npmls
    34. 34. npm install yui3
    35. 35. npm uninstall yui3</li></li></ul><li>Yui3 and node.js<br />
    36. 36. resources<br /><ul><li>http://nodejs.org/
    37. 37. http://npmjs.org/
    38. 38. http://www.yuiblog.com/blog/2010/04/05/running-yui-3-server-side-with-node-js/
    39. 39. http://developer.yahoo.com/yui/3/
    40. 40. http://github.com/davglass/nodejs-yui
    41. 41. http://github.com/davglass/yui-express
    42. 42. http://github.com/harsharv/OpenHackDay2011</li></li></ul><li>Harsha R. Vashishtmail@harsharv.com<br />http://www.harsharv.comhttp://twitter.com/harsharv<br />http://www.facebook.com/harsharvhttp://www.slideshare.net/harsharv<br />http://github.com/harsharv/<br />

    ×