Get Data from POST Requests solution doesn't work for me

Tell us what’s happening:
Describe your issue in detail here.
I kinda gave up on the last node exercise and I tried using the provided solution, but still it doesn’t seem to work.

Code of mine

var express = require(‘express’);

var bodyParser = require(‘body-parser’);

var app = express();

var absolutePath = __dirname + “/views/index.html”

app.post("/name", function(req, res) {

// Handle the data in the request

var string = req.bodyParser.first + " " + req.bodyParser.last;

res.json({ name: string });

});

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:97.0) Gecko/20100101 Firefox/97.0

Challenge: Get Data from POST Requests

Link to the challenge:

EDIT: I also tried the req.body command but that doesn’t seem to work either so I tried bodyParser but it also doesn’t work.

You’re not using bodyParser, you’re only requiring it.

Newer versions of express does not require bodyparser to be installed in your project. It is included by default.

That said, we need to do 2 things here to make it work:

  1. Add app.use(express.json()) after declaring app.
  2. Use req.body instead of req.bodyParser