Created
November 24, 2013 17:09
-
-
Save guo-yu/7629560 to your computer and use it in GitHub Desktop.
just require express-scaffold as a server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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