Skip to content

Instantly share code, notes, and snippets.

@guo-yu
Created November 24, 2013 17:09
Show Gist options
  • Save guo-yu/7629560 to your computer and use it in GitHub Desktop.
Save guo-yu/7629560 to your computer and use it in GitHub Desktop.
just require express-scaffold as a server
var server = require('express-scaffold');
// init a new server running on default port 3000
new server({
name: "just another express app",
desc: "some desciption here",
database: {
name: "expressdemo"
}
})
.models(function($db, $Schema){
var userModel = new $Schema({
name: String,
created: Date,
});
return {
user: $db.model('user', userModel)
}
})
.ctrlers(function($models, $Ctrler){
return {
user: new $Ctrler($models.user)
}
})
.routes(function(app, $ctrlers){
app.get('/', function(req, res, next){
res.send('it just works!');
});
app.get('/users', function(req, res, next){
$ctrlers.user.find({}, function(err, users){
res.json(users);
});
});
})
.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment