Understanding the Request Object in Express.js
In Express.js, we use the req object to get data from the client. Here are some key parts I frequently used:
req.body
req.body holds data sent by the client in a POST request. We use a tool called body-parser to help us read this data.
req.params
req.params is where we find route parameters.
For example, in a route like /user/:id, we can get the id value with req.params.id.
req.query
req.query gives us the URL query parameters. If our URL is /search?q=express, we can get the q value with req.query.q.