-
-
Notifications
You must be signed in to change notification settings - Fork 385
Home
This wiki describes the architecture of the node-express-mongoose boilerplate.
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 the templating system provides.
The views folder contains
-
includes/
- contains
-
head.jade
- meta information, scripts, stylesheets -
header.jade
- contains the logo and the naviagation links -
foot.jade
- usually javascript -
footer.jade
- footer links
-
layouts/
- contains the layout files. - 404 and 500
We are using the view-helpers middleware, which provides some generic methods. If any request comes from a mobile device, then the app automatically tries to look for a .mobile.jade
file and renders it.
For example
res.render('home/index', {
title: 'Welcome to our app'
})
If the request is coming from a mobile device then, the the app tries to look for a index.mobile.jade
, if its there, it tries to render that, otherwise the index.jade
is rendered.
- express
- passport
- routes
- config environments and environment specific stuff