BodyParser Is Deprecated Express 4
Answer :
It means that using the bodyParser() constructor has been deprecated, as of 2014-06-19.
app.use(bodyParser()); //Now deprecated You now need to call the methods separately
app.use(bodyParser.urlencoded()); app.use(bodyParser.json()); And so on.
If you're still getting a warning with urlencoded you need to use
app.use(bodyParser.urlencoded({ extended: true })); The extended config object key now needs to be explicitly passed, since it now has no default value.
If you are using Express >= 4.16.0, body parser has been re-added under the methods express.json() and express.urlencoded().
Want zero warnings? Use it like this:
app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); Explanation: The default value of the extended option has been deprecated, meaning you need to explicitly pass true or false value.
If you're using express > 4.16, you can use express.json() and express.urlencoded()
The
express.json()andexpress.urlencoded()middleware have been added to provide request body parsing support out-of-the-box. This uses theexpressjs/body-parsermodule module underneath, so apps that are currently requiring the module separately can switch to the built-in parsers.
Source Express 4.16.0 - Release date: 2017-09-28
With this,
const bodyParser = require('body-parser'); app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); becomes,
const express = require('express'); app.use(express.urlencoded({ extended: true })); app.use(express.json());
Comments
Post a Comment