There is an in-built middleware present in Express which can handle json/form data in an application.
How to do it?
We just have to write a simple line of code
For JSON data -
app.use(express.json())
For Form data
app.use(express.urlencoded())
What will happen after adding this ?
This will add a property body to request object, which contains all the data in the form of key-value pairs.
How to access data?
app.get('/',(request,response)=>{
console.log(request.body);
})
This will give all the data whether it is JSON or Form data.
Happy Coding