The order of your code matters. You register POST /name before you register the bodyParser middleware. Therefore req.body is undefined when calling POST /name.
I’m sorry I didnt understand what you meant, today is my first day working with express and I dont understand half the stuff that I learnt so far. Could you please help me understand it better, Do you mean the variable bodyParser has to be initialized within the body of app.post?
In Express the middleware is run in the order you register it. So if you don’t register body-parser before POST /name you don’t have access to req.body (which is set by body-parser) inside the function which handles the POST request.