Basic Node and Express - Get Data from POST Requests

Hi everyone.
I tried several times and got an error, it says ‘Your API endpoint should respond with the correct name’. but I don’t know what’s wrong, and my link won’t load the html page. :sob:
Thank you If you figure out how to solve it.

Here is my code:

let express = require('express');
var bodyParse = require('body-parser');
let app = express();

app.use(bodyParse.urlencoded({ extended: false }));
app.use(bodyParse.json)

console.log("Hello World")

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

boilerplate-express - Replit

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/111.0

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

Link to the challenge:

You’re missing a chunk of code in your file, most importantly your GET ‘/’ route, which serves the index.html file, without which you can’t pass the challenge.

Also, you need to include a pair of parentheses after ‘json’ in this line:

app.use(bodyParse.json)

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