210 likes | 602 Views
Node.js Packages. March 13, 2012 Shamoon Siddiqui @ shamoons. What are packages?. Ruby has Gems Python has Py PI 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.
E N D
Node.js Packages March 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 Development • Routing • Sessions • Templating • $: npm install –g express • $: express mysite
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 Finding Model.find({name: “shamoon”}, function(err, data){console.log(data);}) Model.findOne() Model.findById()
async • Callbacks are awesome • Except when they’re nested • Unless they’re well managed • Then nesting doesn’t become a huge issue • But it is still difficult to read • A function within a function • …within a function
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