Third-party Middleware: Third-party middleware are external packages that enhance Express’s functionality. They can be easily integrated into your application.
Example: Body parsing middleware using the body-parser
package
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
// Third-party middleware for parsing JSON and URL-encoded bodies
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.post('/data', (req, res) => {
console.log(req.body);
res.send('Data received');
});
app.listen(3000, () => {
console.log('Server is running on port 3000');
});