-
-
Notifications
You must be signed in to change notification settings - Fork 385
Home
This wiki describes the architecture of the node-express-mongoose boilerplate.
The app
and config
folder holds the core of the application. app
consists of models, views, controllers and mailers.
Simply drop a mongoose model file in the app/models/
directory and make sure the schema is defined
var mongoose = require('mongoose')
var Schema = mongoose.Schema
var UserSchema = new Schema({
name: { type: String, default: '' },
email: { type: String, default: '' },
hashed_password: { type: String, default: '' },
salt: { type: String, default: '' }
})
and is exposed using
// after schema declaration
mongoose.model('User', UserSchema)
As you can see in the user model file, we are using mongoose-user plugin - which does the validations and provides some generic statics like list and load.
Further down, you can use these list and load methods to write your own statics. For example
somewhere in your admin or controller
User.deleted(function (err, users) {
// do your stuff
// `users` is an array of deleted users
})
in app/models/user.js
UserSchema.static({
/**
* Lists all the deleted users
*/
deleted: function (cb) {
this.list({
criteria: { deleted: true },
sort: { name: 'desc' }
limit: 20,
populate: [{
path: 'company', select: 'name', match: { deleted: false }
}],
select: 'name email'
}, cb)
}
})
The views are located in app/views/
directory. The boilerplate uses jade
as the templating system. If you want to use ejs (also use ejs-locals) or any other templating system, rename the .jade
files to .ejs
or whatever extension templating system requires.
The views folder defaultly contains
-
includes/
- which contains a.head.jade
- meta information, scripts, stylesheets b.header.jade
- contains the logo and the naviagation links c.foot.jade
- usually javascript d.footer.jade
- footer links -
layouts/
- usually contains the page layouts. - 404 and 500
- Passport
- Express
- Config environments and environment specific stuff