can u explain briefly how does this works?
What does express.json and express.urlencoded do in the post req
Hi @aditya010sh_cda2cad8fd454417,
Middleware are those methods which are called while processing the request and sending response in the application. Express provides you with middleware to deal with the data in the body of the request.
express.json()
and express.urlencoded()
is for post & put requests, because in these requests you are sending data in the form of some json data object to server and you are asking the server to accept or store that data, which is enclosed in the body (i.e. req.body
) of that post or put request.
To go by definition :
express.json()
is a method which is inbuilt in express to handle incoming request object as a json object . Returns middleware that only parses json
.
whereas, express.urlencoded()
is a method that is also inbuilt in express to handle incoming request object as strings or arrays . It returns middleware that only parses urlencoded
with the qs module.
To read more about there use and description please refer the below given links. These articles briefly explain the use and need for both.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.