Basic Node and Express - Serve JSON on a Specific Route

Tell us what’s happening:
Describe your issue in detail here.

I have this code in Repl.it IDE.


app.use("/public", express.static(__dirname+"/public"));

app.get("/json", (req, res) => {
  res.json({
    message: "Hello json",
  });
});

app.get("/", (request, response) => {
  let absolutePath = __dirname + "/views/index.html";
  response.sendFile(absolutePath);
})

but the following test fails… and says that

    • The endpoint /json should serve the json object {"message": "Hello json"}*

Where am I going wrong?
Your project link(s)

solution: boilerplate-express - Node.js Repl - Replit

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Safari/537.36 Edg/104.0.1293.70

Challenge: Basic Node and Express - Serve JSON on a Specific Route

Link to the challenge:

It has been submitted. Thank You!
It was a silly overlook sorry.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.