Created
January 5, 2016 12:33
-
-
Save roberto/73d277c73bf30b577414 to your computer and use it in GitHub Desktop.
restify + mongoose
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 restify = require('restify'); | |
var mongoose = require('mongoose'); | |
mongoose.connect('mongodb://localhost/spike'); | |
var db = mongoose.connection; | |
db.on('error', console.error.bind(console, 'connection error:')); | |
db.once('open', function() { | |
console.log('yay'); | |
}); | |
var Point = mongoose.model('Point', mongoose.Schema({ | |
x: Number, | |
y: Number | |
}) | |
); | |
//var point = new Point({x: 2, y: 2}); | |
//point.save(); | |
function respond(req, res, next) { | |
Point.find({}, function (err, points) { | |
if(err) console.log(err); | |
res.send(points); | |
next(); | |
}); | |
} | |
var server = restify.createServer(); | |
server.get('/points', respond); | |
server.listen(8080, function() { | |
console.log('%s listening at %s', server.name, server.url); | |
}); |
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
brew install nodejs mongodb | |
npm install --save mongoose restify |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment