Skip to content

Instantly share code, notes, and snippets.

@vdeturckheim

vdeturckheim/getCats.js Secret

Last active Nov 21, 2017
Embed
What would you like to do?
'use strict';
const Express = require('express');
const Mongoose = require('mongoose');
const app = Express();
Mongoose.connect('mongodb://localhost/test', { useMongoClient: true });
Mongoose.Promise = global.Promise;
const Cat = Mongoose.model('Cat', { name: String });
app.get('/cats', async (req, res, next) => {
// this route simply list the content of the 'Cat' collection
try {
const cats = await Cat.find().exec(); // using await syntax make it much simpler here
return res.json(cats);
}
catch (e) {
return next(e);
}
});
app.listen(9090, () => {
console.log('server running on port 9090');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.