Categories
JavaScript Answers

How to fix the ‘BodyParser is deprecated’ warning with Node.js and Express?

Spread the love

Sometimes, we want to fix the ‘BodyParser is deprecated’ warning with Node.js and Express.

In this article, we’ll look at how to fix the ‘BodyParser is deprecated’ warning with Node.js and Express.

How to fix the ‘BodyParser is deprecated’ warning with Node.js and Express?

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

For instance, we write

app.use(express.urlencoded({
  extended: true
}));
app.use(express.json())

to call app.use with the middlewares returned by express.urlencoded and express.json to let us parse URL encoded and JSON request bodies.

Conclusion

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

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *