Introduction to







SERVER-SIDE JAVASCRIPT FRAMEWORK FOR BUILDING SCALABLE WEB APPS

Nishant Srivastava @ Mindfire Solutions

AGENDA

  1. Introduction
  2. Blocking Vs Non Blocking I/O 
  3. Installation
  4. NPM
  5. Express.js
  6. Other Modules
  7. Cloud9 IDE
  8. Demo
  9. Questions


Introduction


What is Node.js



Server-Side 
JavaScript
Created by Ryan Dahl in 2009
Platform built upon Google's V8-JavaScript Engine
Event Driven, Non-Blocking I/O
Perfect for data-intensive real-time applications
High Concurrency

Basic Modules


EVENT DRIVEN, NON BLOCKING I/O MODEL


TRADITIONAL WEB SERVER

Uses threads to handle incoming requests


NODE.JS

Uses single non-blocking thread with an event loop

Who is using Node.js


  • eBay
  • Yahoo
  • Linkdin
  • Microsoft
  • Walmart
  • Yammer
  • Voxer
  • ....

Why Node.JS ?


  • Non-Blocking I/O (FAST !)
  • Highly efficient scalability 
  • Google's V8-JS Engine (FAST!)
  • 15,000+ Modules (..and counting..)
  • Active Community ( IRC, Mailing List, Twitter, Git)
  • Cross Platform (Mac, Linux, Windows)
  • Javascript: 1 Language for Frontend and Backend
  • JSON friendly (Client, Server, Database)

What CAN YOU BuiLD


WEB APPLICATIONS
CUSTOM WEB SERVERS
STREAMING DATA
REALTIME APPS
OS INTEGRATED TOOLS
MIDDLEWARE
ELECTRONICS/ROBOTS

Blocking Vs Non-Blocking I/O

  
       Blocking I/O
          1. Synchronous I/O
          2. Wait for I/O operation to complete
          3. Idle time
       Non-Blocking I/O
          1. Asynchronous I/O
          2. Continuous processing
          3. Improved throughput and latency 

Installation


  On Windows
  On MacOS
http://nodejs.org/dist/v0.10.5/node-v0.10.5.pkg
  On Linux
sudo apt-get update && sudo apt-get install curl build-essential openssl libssl-dev git python


Packages? Enter NPM

It's how you harness the #awesomeness of the node.js community!


Node Package Manager

npmjs.org

Using NPM

$ npm install <packagename>i.e $ npm install express 
or 
create package.json manifest
{
  "name": "hello-node",
  "description": "hello world",
  "version": "0.0.1",
  "dependencies": {
    "express": "3.x"
  }
}
$ npm install

EXpress.js

Web Application Framework For Node.JS

  • Inspired by Sinatra (Ruby)
  • Fast, un-opinionated, minimalist web framework for node
  • template engine support (Jade, EJS)
  • CSS engine support (SASS,LESS,Stylus)
  • Asynchronous
  • Based On Connect Middleware
  • Implements MVC

expressjs.com

Using Express.JS

    INSTALLATION

$ node install express -g

Generating a Basic App

$ express myapp$ cd myapp && npm install$ node myapp

Other Modules


Jade Template Engine
http://jade-lang.com/
Stylus CSS Engine 
http://learnboost.github.io/stylus/
MONGO DB
HTTP://WWW.MONGODB.ORG/


Cloud9 IDE


Online IDE for Node.js
Supports Code Completion just like VS
Easy to code,run and deploy

ScreenShot


DEMO


Setting up a basic Server



var http = require("http");
http.createServer(function(req, res){
   res.writeHead(200, {"Content-Type": "text/plain"});
   return res.end("Hello Node Developer!\n");
}).listen(8080);
console.log("Server running at port 8080"); 


Questions ?


Thank You

Introduction to Node.JS

By Nishant Srivastava

Introduction to Node.JS

Basic intro of node.js

  • 2,427