Skip to content

Instantly share code, notes, and snippets.

@curiousily
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save curiousily/32fd18f3f55c553c9601 to your computer and use it in GitHub Desktop.
Save curiousily/32fd18f3f55c553c9601 to your computer and use it in GitHub Desktop.
Wire up co, hapi, mongoose and node 0.11.9+ --harmony
var Mongoose = require('mongoose')
var Hapi = require('hapi')
var Co = require('co')
Mongoose.connect('mongodb://localhost/mytestdb')
var userSchema = Mongoose.Schema({
name: String
})
var User = Mongoose.model('User', userSchema)
var server = new Hapi.Server();
server.connection({
host: 'localhost',
port: 8000
});
server.route({
method: 'GET',
path:'/hello',
handler: function(request, reply) {
var wrapper = Co.wrap(function* (request, reply) {
var user = new User({name: "John"})
var newUser = yield user.save()
var users = yield User.find().exec()
reply([newUser, users])
})
wrapper(request, reply)
}
});
server.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment