Basic Node and Express - Serve JSON on a Specific Route

Tell us what’s happening:
Describe your issue in detail here.
I run it but it not works.Thanks for reply
This is my code:

let express = require('express');
let app = express();

console.log("Hello World");

app.get("/", function(request, response)  {
  response.sendFile(__dirname + "/views/index.html");
});

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

//Serve JSON on a Specific Route
app.get("/json", function(request, response) {
  response.json(
    { "message": "Hello json" } 
  );
});
module.exports = app;

Your project link(s)

solution: boilerplate-npm - Replit

Your browser information:

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

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

Link to the challenge:

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

The link you provided to your repl is not valid (not found).
This one appears to be the correct repl however:
https://replit.com/@hoang-phuc-tien/boilerplate-express

You’ve commented out the code which is required to pass this step. I forked it, uncommented the code and it passed for me.

Remember you should be submitting the live url:
https://boilerplate-express.hoang-phuc-tien.repl.co/

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