Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

express throws error as `body-parser deprecated undefined extended`

People also ask

How do you solve a deprecated body-parser?

To fix the 'BodyParser is deprecated' warning with Node. js and Express, we can replace bodyParser with express. urlencoded and express. json .

Is body-parser deprecated in Express?

'bodyParser' is deprecated. // If you are using Express 4.16+ you don't have to import body-parser anymore.

What is express Urlencoded?

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.