Node.js PackagesMarch 13, 2012
Shamoon Siddiqui@shamoons
What are packages?
• Ruby has Gems• Python has PyPI• PHP has PEAR (terrible)
• Node.js has Packages
Node Package Manager (NPM)
• Get NPM at http://npmjs.org/• Almost 8,000 packages!• Seriously... one line install
curl http://npmjs.org/install.sh | sh
Awesome Packages
• express• mongoose• async• socket.io• request
express
• Kickass Framework for Web Application Developmento Routingo Sessionso Templating
$: npm install –g express$: express mysite
routes/index.js
mongoose
• MongoDB is awesome (look at where we are!!!!)
• Interaction with MongoDB via an ODM• Keeps Code Clean
Models
Screenshots from MongooseJs.com
Mongoose Functions
FindingModel.find({name: “shamoon”}, function(err, data){
console.log(data);})
• Model.findOne()• Model.findById()
async
• Callbacks are awesomeo Except when they’re nested
Unless they’re well managed• Then nesting doesn’t become a huge issue
o But it is still difficult to read A function within a function
• …within a function
WTF??
Adapted from Ryan Roemer (@ryan_roemer)
Control Flow
Series• series• waterfall
Parallel• parallel• queue
socket.io
Server Client
Emit and Receive
• Basic model is to "emit" an event with data• Received "listens" for events• Acts on reception of event• Client or Server can be emitter or listener
request
• HTTP Requests made easy• POST• GET• JSON• XML
Instant Proxy Server!
https://github.com/mikeal/request
Questions?
Shamoon Siddiqui@shamoons
Top Related