javascript - How to structure a express.js application? -


is there common convention breaking , modularizing app.js file in express.js application? or common keep in single file?

i have mine broken follows:

~/app |~controllers | |-monkey.js | |-zoo.js |~models | |-monkey.js | |-zoo.js |~views | |~zoos |   |-new.jade |   |-_form.jade |~test |  |~controllers |    |-zoo.js |  |~models |    |-zoo.js |-index.js 

i use exports return what's relevant. instance, in models do:

module.exports = mongoose.model('phonenumber', phonenumberschema); 

and if need create phone number, it's simple as:

var phonenumber = require('../models/phonenumber'); var phonenumber = new phonenumber(); 

if need use schema, phonenumber.schema

(which assumes working routes folder , need go 1 level , down models)


edit 4

the express wiki has list of frameworks built on top of it.

of those, think twitter's matador structured pretty well. used similar approach how load parts of app.

derby.js looks extremely interesting. it's akin meteor without of hype , gives credit credit due (notably, node , express).


edit 3

if fan of coffeescript (i not) , reeeeaaaaaally want l&f of rails, there tower.js.


edit 2

if familiar rails , don't mind bleed-over of concepts there locomotive. light-weight framework built on express. has similar structure ror , carries on of more rudimentary concepts (such routing).

it's worth checking out if don't plan use it.


edit 1

nodejs-express-mongoose-demo similar how have mine structured. check out.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -