HELLO WORLD
Jeff Andersen Developer Twitter: @jeffandersen Email: jeff@goinstant.com
What is Node.js? • In a nutshell: server-side JavaScript • Used to build scalable network applications • Built on Google’s v8 JavaScript engine • Event-driven, non-blocking (asynchronous) I/O
Who uses it?
Installing Node.js • Visit nodejs.org • Download the package/installer and run • Alternatively: use nvm - Node Version Manager
 (Similar to Ruby’s RVM)
 https://github.com/creationix/nvm
Test out the repl • From the command line type `node` • Type out commands and hit enter
Use cases • REST APIs • Streaming data • High concurrency • Leveraging UNIX tools • Realtime applications
Event Driven
Event Driven
Sync vs Async
Synchronous (Blocking)
Asynchronous (Non-Blocking)
Asynchronous (Non-Blocking) • Node is built for async i/o • Sometimes difficult to understand • Callback soup
Let’s run it
HTTP Server
5 lines of code Let’s run it
HTTP Server
Community / Ecosystem http://notinventedhe.re/on/2011-7-26
• npmjs.org • Open source software • Official package manager for Node.js • Nearly 55 thousand packages and almost 2.5 million downloads per day • package.json
Package.json
npm install
Recommended Modules • async - Higher-order functions and common patterns for asynchronous code • lodash - A utility library delivering consistency, customization, performance, & extras. • express - Sinatra inspired web development framework • mocha - simple, flexible, fun test framework • pg - PostgreSQL client • redis - Redis client
Example app
Example app Basic REST api
What do we need? • HTTP server • Postgres database • Postgres client • JSON formatted responses
We have an HTTP server
Problems? • One handler replying to every request • Missing • Routing/URL parameters • Response formatting
Introducing Express • npm install express • Sinatra style web framework • Simple verb-based request handlers • Full-featured router • • body parser, url parameters, query string parsing Automatic response formatting
Same functionality
Let’s code
What could be added? • OAuth middleware • Middleware: A function that processes a request, typically on an interim basis to the final request handler. • Permissions & token scopes • JSON web hooks
Twitter recommendations • @izs - Isaac Schlueter, Creator of NPM & Node core gate keeper • @eranhammer - Eran Hammer, Walmart Labs & OSS contributor • @substack - James Halliday, Node module authoring machine • @tjholowaychuk - TJ Holowaychuk, Author: Express, Mocha, etc • @igrigorik - Ilya Grigorik, Developer advocate at Google • @jeresig - John Resig, Creator of jQuery • @goinstant - Realtime Collaboration API and Backend
Hello world - intro to node js

Hello world - intro to node js