hacking with node.JS
Upcoming SlideShare
Loading in...5
×
 

hacking with node.JS

on

  • 7,822 views

Getting started with node.JS

Getting started with node.JS

Statistics

Views

Total Views
7,822
Views on SlideShare
7,774
Embed Views
48

Actions

Likes
5
Downloads
76
Comments
1

3 Embeds 48

https://pulse.neudesic.com 44
http://twitter.com 2
https://twitter.com 2

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

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…
  • let's 'right' some modules :D LOL
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • 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 hacking with node.JS Presentation Transcript

  • #hacking withnode.JS
    HarshaVashisht
    http://www.harsharv.com
    @harsharv
    Picture Source: http://bethesignal.org/blog/2011/01/06/speaking-lca2011-html5-nodejs/
  • What is node.js?
  • Node is an exciting new platform developed byRyan Dahl.
  • It is a lot of sugar on v8
  • It allows JavaScript developers to create extremely high performance servers by leveraging Google's V8 JavaScript engine, and asynchronous I/O.
  • Never wait it the motto
  • Recap… What is Node.js?
    • Node is an exciting new platform developed by Ryan Dahl.
    • It allows JavaScript developers to create extremely high performance servers by leveraging Google's V8 JavaScript engine, and asynchronous I/O.
    • Node is a lot of Sugar written on V8
    • Never wait is the motto. Either to fetch a page from the web or fetch data from a DB.
  • let us look at…
  • DUCK! There will be code…
    Lets see cod
  • LAMP STACK
    1. Order
    2. Waits for the food
    to be cooked
    3.Food is ready
    4. Serve
  • Node JS
    1. Order
    2. Places the order
    with the cook
    3. Immediately moves on to take the order from the next table
    4. Cook notifies that the food is
    ready
    5. Food is served
  • commonjs
    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.*
    * Conditions Apply
  • Why node.js?
  • Global objects
    • Require
    • Module/ export
    • Process
  • Require
    This is used to specify that a module is required.
    Example:
    var operation = require(“pow”)
  • Module/ exports
    This is used to package JavaScript libraries and expose the functionality to be used else where.
    Example:
    exports.pow = function (a, b) {

    }
  • process
    • The process object is a global object and can be accessed from anywhere.
    • It is an instance of EventEmitter.
    • Can be thought as an equivalent to Window object in the browser
    Examples:
    • process.cwd()
    • process.exit(1)
    • process.argv
    • process.on('exit', function () {
    ...}
    • process.on('uncaughtException', function (err) {
    …}
  • Simple http server
    /* File Name: hello-server.js */
    /* Include the http module. */
    var http = require('http');
    /* Create a server which accepts Request - req and returns Response - res */
    http.createServer(function (req, res) {
    /* Set the HTTP header for the response. */
    res.writeHead(200, {'Content-Type': 'text/plain'});
    /* End the HTTP response */
    res.end('Hello Worldn');
    }).listen(9000, "127.0.0.1");
    /* Print a message to indicate that the server is running. */
    console.log('Server running at http://127.0.0.1:9000/');
  • Modules lets right some
  • Calculate power of a number
    exports.pow = function (a, b) {
    /* Check if a number is passed. */
    if (isNaN (a-0) || isNaN (b-0)) {
    return null;
    }
    varans = 1;
    for (vari = 1; i <= b; i++) {
    ans *= a;
    }
    return ans;
    }
    Link: https://github.com/harsharv/OpenHackDay2011/blob/master/hello-server.js
  • twitter search module
    https://github.com/harsharv/OpenHackDay2011/blob/master/twitter.js
    https://github.com/harsharv/OpenHackDay2011/blob/master/mashup.js
  • Npm – node package manager
    • npm is the package manager for the Node JavaScript platform
    • It puts modules in place so that node can find them, and manages dependency conflicts intelligently.
  • More about npm
    • Install NPM
    curl http://npmjs.org/install.sh | sh
    • Browse the packages of NPMhttp://search.npmjs.org/
  • Npm basic commands
    • npm search
    • npmls
    • npm install yui3
    • npm uninstall yui3
  • Yui3 and node.js
  • resources
    • http://nodejs.org/
    • http://npmjs.org/
    • http://www.yuiblog.com/blog/2010/04/05/running-yui-3-server-side-with-node-js/
    • http://developer.yahoo.com/yui/3/
    • http://github.com/davglass/nodejs-yui
    • http://github.com/davglass/yui-express
    • http://github.com/harsharv/OpenHackDay2011
  • Harsha R. Vashishtmail@harsharv.com
    http://www.harsharv.comhttp://twitter.com/harsharv
    http://www.facebook.com/harsharvhttp://www.slideshare.net/harsharv
    http://github.com/harsharv/