19
Node.js Packages March 13, 2012 Shamoon Siddiqui @shamoons

Node.js Packages

Embed Size (px)

DESCRIPTION

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. - PowerPoint PPT Presentation

Citation preview

Page 1: Node.js Packages

Node.js PackagesMarch 13, 2012

Shamoon Siddiqui@shamoons

Page 2: Node.js Packages

What are packages?

• Ruby has Gems• Python has PyPI• PHP has PEAR (terrible)

• Node.js has Packages

Page 3: Node.js 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

Page 4: Node.js Packages

Awesome Packages

• express• mongoose• async• socket.io• request

Page 5: Node.js Packages

express

• Kickass Framework for Web Application Developmento Routingo Sessionso Templating

$: npm install –g express$: express mysite

Page 6: Node.js Packages
Page 7: Node.js Packages

routes/index.js

Page 8: Node.js Packages

mongoose

• MongoDB is awesome (look at where we are!!!!)

• Interaction with MongoDB via an ODM• Keeps Code Clean

Page 9: Node.js Packages

Models

Screenshots from MongooseJs.com

Page 10: Node.js Packages

Mongoose Functions

FindingModel.find({name: “shamoon”}, function(err, data){

console.log(data);})

• Model.findOne()• Model.findById()

Page 11: Node.js Packages

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

Page 12: Node.js Packages

WTF??

Page 13: Node.js Packages

Adapted from Ryan Roemer (@ryan_roemer)

Page 14: Node.js Packages

Control Flow

Series• series• waterfall

Parallel• parallel• queue

Page 15: Node.js Packages

socket.io

Server Client

Page 16: Node.js Packages

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

Page 17: Node.js Packages

request

• HTTP Requests made easy• POST• GET• JSON• XML

Page 18: Node.js Packages

Instant Proxy Server!

https://github.com/mikeal/request

Page 19: Node.js Packages

Questions?

Shamoon Siddiqui@shamoons