Quantcast
Channel: Node GET request is hanging unable to finish the request and the page keep loading - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Node GET request is hanging unable to finish the request and the page keep loading

$
0
0

SOLVED

I am currently building an app with Node - Express - MongoDB - ejs.

I have a books router that should render the books ejs file and books list from MongoDB.Here's the books.js code:

const express = require("express");const router = express.Router();const { MongoClient } = require("mongodb");router.route("/").get(async (req, res, next) => {  const url = "mongodb://localhost:27017";  const dbName = "Library";  let client;  try {    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) {    res.send(err);  }});module.exports = router;

It is supposed to get the data from the MongoDB and send it back to the books page instead I get this error{ "code": "ERR_INVALID_ARG_TYPE" }


Viewing all articles
Browse latest Browse all 3

Trending Articles