let messages = await db.collection(`messages`).find().toArray()The find method could take some time to complete, so
await
is used, which means async
must be
placed on front of the function:
app.get(`/messages`, async (request, response) => {