Last active
August 29, 2015 14:11
-
-
Save curiousily/32fd18f3f55c553c9601 to your computer and use it in GitHub Desktop.
Wire up co, hapi, mongoose and node 0.11.9+ --harmony
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 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