Node.js Packages - Meetup

gayheadtibburInternet and Web Development

Feb 5, 2013 (4 years and 6 months ago)

166 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


curl http://
npmjs.org
/
install.sh

|
sh


Awesome Packages


e
xpress


m
ongoose


a
sync


socket.io


request

express


Kickass Framework for Web Application
Development

o
Routing

o
Sessions

o
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

Finding

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


console.log
(data);

})



Model.findOne
()


Model.findById
()

async


Callbacks are awesome

o
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

Adapted from Ryan Roemer
(
@ryan_roemer
)

Control Flow

Series


series


waterfall


Parallel


p
arallel


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