In the code snippet below, do I need to use the urlencodedParser like I do in Post methods.
app.put('/api/provider/:id', urlencodedParser, function (req, res) {
}
body-parser
parses the body of the request into req.body
, which you'll likely need for your put
middleware. body-parser
now comes built into Express (as of v4.16.0 - below assumes you have an updated version).
The easiest implementation is to use express.json
and express.urlencoded
(used in body-parser
) in all requests, using app.use
, so that you don't have to worry about it in your middleware. Here is how npx express-generator $APP_NAME
will set it up for you:
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
NOTE: You'll need to set extended
to true
if you are expecting nested objects in your requests.