Basic Node and Express - Get Data from POST Requests

Tell us what’s happening:
Describe your issue in detail here.
Completed with two possible ways to see if it could be the way to solve the one that was not accepted.

app.post(“/name”, (req, res)=>{
let first = req.body.first
let last = req.body.last
let string = first + " " + last;
res.json({ name: string })
})

app.post(“/name”, (req, res)=>{
let string = req.body.first + " " + req.body.last;
res.json({ name: string })
})

However, although the name was displayed on the screen, it disappeared after a very short while in the replit webview console. In a new tab, the {“name”:“Johns Does”} remains.

All the best

solution: boilerplate-express (3) - Replit

Your browser information:

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

Challenge: Basic Node and Express - Get Data from POST Requests

Link to the challenge:

1 Like

Your repl passes the challenge for me. Nothing wrong with your code I think.
I don’t know why, but after the POST request sends the json response, a GET request is sent, which comes up with ‘undefined’ values in the response object, overriding the response sent by the POST.
If you open the ‘/name’ url in a separate tab, as you say, the correct response object remains… until you refresh the screen (which sends a GET request which will be ‘undefined’).
The reason it’s undefined is that there’s no query string included.
The only bit I don’t understand is why a GET request is sent to the repl webview window.

1 Like

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