Getting Started With
Node.js and mongoDB
Grant Goodale (@ggoodale)
What is ?
Application engine for “scalable network applications”
Really freaking fast:
One process, zero* threads
(Almost) no blocking
* actually, there is a thread pool. We’ll get to that.
What is ?
High concurrency with low overhead
No thread swapping or context switching
Applications must be designed from the ground up to
not block on I/O, CPU-intensive work, etc.
What Node.js Isn’t
A full-stack web framework (a la Ruby on Rails)
But! you can get there:
ExpressJS: (http://expressjs.com/) (Web framework
with MongoDB support built in - similar to Sinatra)
middleware for Node and Express)
haml.js: http://github.com/visionmedia/haml.js (Pure
js implementation of HAML)
What Node.js Isn’t (cont.)
Great at sending large static ﬁles concurrently. (use
Buffer implementation in recent versions improves
this dramatically: http://nodejs.org/jsconf2010.pdf
CPU-intensive stuff will still block you (do it in a
Some system calls (executed in a thread pool)
Great together! Both:
understand JSON documents
are freaking fast.
So, what should you build?
You can build: Standard n-tier web applications
Great way to learn mongoDB and Node
Go build a blog engine! (Everyone does.)
Lots of libraries to help you get started: ExpressJS,
You should build:
Applications requiring high throughput and
Applications with real-time needs
Applications with long-polling connections
Real-time multiuser chat
Web or log analytics (e.g. Hummingbird)
Grab the following:
npm, a package manager for Node:
curl http://npmjs.org/install.sh | sh
Use npm to install a mongoDB driver for Node:
npm install mongodb
Tons of other fun stuff as well - full package list at
Other Fun Stuff:
extensions? We got 'em.)
Routers, ﬁle servers, frameworks, crypto...
http://socket.io/: Cross-platform WebSockets
Supports HTML5 websockets
Falls back to Flash / AJAX in less capable browsers