Tell us what’s happening:
Describe your issue in detail here.
endpoint /json should serve the JSON object {"message": "Hello json"}
i compared with
the tip is this:
app.get("/json", (req, res) => {
res.json({
message: "Hello json"
});
});
i dont see the error in my source of the app:
let express = require('express');
let app = express();
const path = require('path');
app.listen(80);
console.log("Hello Express");
// console.log('__dirname=' + __dirname); // __dirname=/home/runner/boilerplate-express
app.get("/", (req, res) => {
// res.sendFile('/views/index.html');
res.sendFile(path.join(__dirname, '/views/index.html'));
});
app.get("/json", (req, res) => {
res.json({
message: "Hello json"
});
});
// Assets at the /public route
app.use('/public', express.static(__dirname + '/public'));
module.exports = app;
Your project link(s)
solution: boilerplate-express - Replit
Your browser information:
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/110.0
Challenge: Basic Node and Express - Serve JSON on a Specific Route
Link to the challenge: