Node.js and friends

Click here, Press key to advance.

Presented at D. E. Shaw India, Hyderabad (18-Jul-2012)

Navigation

  • [arrow keys] to go next and previous

  • [mouse scroll wheel] to go next and previous

  • [Ctrl or Command] + [+/-] to zoom in and out

  • [touch gestures] for mobile devices

Agenda

  • [Demo] DESIS Hackathon app
  • Node.js
  • Express.js
  • Web Sockets
  • Mongo DB

Disclaimer: I am not an expert in any of these.

Node.js

  • Platform built on Chrome's JavaScript runtime (V8) for easily building fast, scalable network applications.
  • Event driven "Server Side" JavaScript
  • Non-blocking I/O. Async model.
    • Event loop
    • libev, libeio
  • Authored by Ryan Dahl. Sponsored by Joyent
  • Alternatives: Twisted for Python, Event Machine for Ruby

Node.js - Getting Started

  • Installation
    • Using Installers - Mac, Linux and Windows
    • using Package Managers - Mac and Linux
    • Build from source - Mac and Linux
  • node REPL
  • Hello World
  • Diving into Node.js #shamelessplug

Node.js - Concurrency

  • I/O bound vs CPU bound
  • Everything is asynchronous except your code
  • Non-blocking I/O. Async model.
    • Event loop
    • libev, libeio
  • Single stack environment
  • Multi-processor concurrency?
    • child_process.fork()
    • For load balancing, use cluster module
  • Ref: Node.js from Enterprise Java Perspective

Node.js - Globals

  • global
  • process
  • console
  • require()
  • require.resolve()
  • require.cache
  • require.extensions [array]
  • __filename, __dirname
  • module, exports
  • setTimeout, clearTimeout
  • setInterval, clearInterval

Node.js - Modules

  • Each file is a module
    • Core Modules (fs, os, http)
    • File Modules
  • Module extensions (.js, .json, .node)
  • Module resolution
  • Cycles
  • Module caching
  • Node Package Manager - npm
  • Modules wiki

Node.js - Frameworks

Express.js

  • High performance, high class web development for Node.js
  • Built on top of Connect
  • Installation via npm
  • Project template generation
  • Features
    • Robust routing
    • View rendering (Jade)
    • Environment based configuration (NODE_ENV)
    • Settings - Internal & arbitary settings
    • Session support
    • Middleware

Web Sockets

The Awesome 'Socket.io'

  • WebSocket-compatible server and client with fallback for legacy browsers
  • Storing data associated with a client
  • Namespace restriction
  • Acknowledgements are possible
  • Multiple transports and fallback
  • More info: socket.io | Github

Socket.io - Browser Support

Transports
  • WebSocket
  • Adobe® Flash® Socket
  • AJAX long polling
  • AJAX multipart streaming
  • Forever Iframe
  • JSONP Polling

Browsers
  • Internet Explorer 5.5+
  • Safari 3+
  • Google Chrome 4+
  • Firefox 3+
  • Opera 10.61+

mongo DB {name:"mongo", type: "DB"}

Scalable, high-performance, open source NoSQL database. Written in C++.

Features:
  • Document Oriented Storage
  • Full Index Support
  • Replication & High Availability
  • Auto Sharding
  • Querying
  • Map/Reduce
  • Fast In-Place updates

Node.js driver, ORM and more about this later...

Thank You