Skip to content

Instantly share code, notes, and snippets.

@roelvan
Last active December 6, 2018 17:17
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 roelvan/411d1887a47c98ce8a35507ccdf3def4 to your computer and use it in GitHub Desktop.
Save roelvan/411d1887a47c98ce8a35507ccdf3def4 to your computer and use it in GitHub Desktop.
Lambda node micro example
const { send } = require('micro');
const cors = require('micro-cors')();
const { handleErrors } = require('errors');
const mongo = require('mongo');
const COLLECTION_NAME = 'games_v3';
const handler = async (req, res) => {
const db = await mongo();
const games = db.collection(COLLECTION_NAME);
const [quizzes, total] = await Promise.all([
games
.find({})
.limit(30)
.toArray(),
games.countDocuments({})
]);
send(res, 200, { total, data: quizzes });
};
module.exports = handleErrors(cors(handler));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment