To fix the 'BodyParser is deprecated' warning with Node. js and Express, we can replace bodyParser with express. urlencoded and express. json .
'bodyParser' is deprecated. // If you are using Express 4.16+ you don't have to import body-parser anymore.
urlencoded() is a built-in middleware in Express. js. The main objective of this method is to parse the incoming request with urlencoded payloads and is based upon the body-parser. This method returns the middleware that parses all the urlencoded bodies.
You have to explicitly set extended
for bodyParser.urlencoded()
since the default value is going to change in the next major version of body-parser
. Example:
app.use(bodyParser.urlencoded({ extended: true }));
Since express
4.16.0, you can also do:
app.use(express.urlencoded({ extended: true }))
Attention: With express version => 4.16.0
the body-parser
middleware was added back under the methods express.urlencoded()
and express.json()
Which can be used as:
app.use(express.urlencoded({extended: true}));
app.use(express.json());
The error says you need to provide the extended option for the body-parser like so:
app.use(bodyParser.urlencoded({ extended: false }))
If you facing 'bodyParser' is deprecated.
Just do
app.use(express.urlencoded({extended: true}));
app.use(express.json());
Note: If you are using 4.16.0
or later express version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With