You define a function called mongo
but then you never call it.
Since you never call it, you never call res.render
.
Even if you did call it, in the catch
branch you never send an error response either.
It looks like you intended it to be an IIFE but forgot the ()
afterwards. There's no need for that though, you can just make the function you pass as the second argument to get()
async
instead.
router.route("/").get(async (req, res) => { const url = "mongodb://localhost:27017"; const dbName = "Library"; try { const client = await MongoClient.connect(url, { useUnifiedTopology: true }); const db = client.db(dbName); const books = await db.collection("books").find().toArray(); res.render({ title: "Books", books, }); } catch (err) { console.log(err); res.status(500).json({error: err}) } });