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-parser
module 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());