bodyparser deprecated code example

Example 1: express bodyparser deprecated

The package bodyParser is deprecated. You will get this warning with these lines of code:

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

If you are using Express 4.16+ you can now replace those lines with:

app.use(express.json()); 
app.use(express.urlencoded()); //Parse URL-encoded bodies

Example 2: body parser deprecated

const express = require('express');

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

Example 3: express bodyparser deprecated

body-parser has been deprecated from express v4.* 
Use body-parser package instead.
npm i body-parser

import bodyParser from "body-parser";//for typscript code only, use require for js
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

Example 4: body-parser deprecated

app.use(bodyParser.urlencoded());

app.use(bodyParser.json());

Example 5: body parser deprecated

const bodyParser  = require('body-parser');

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

Example 6: 'bodyParser' is deprecated.

app.use(bodyParser.urlencoded());

app.use(bodyParser.json());

Tags:

Misc Example