Google News
logo
Express.js - Interview Questions
Explain some third-party middleware provided by Express.js.
Third-party Middleware: There are many third-party middleware available such as :
 
* Body-parser
* Cookie-parser
* Mongoose
* Sequelize
* Cors
* Express-validator
 
To handle HTTP POST requests in Express.js version 4 and above, we have to install a middleware module called body-parser. Body-parser extracts the entire body portion of an incoming request stream and exposes it on req. body, The Middleware was a part of Express.js earlier, but now you have to install it separately. You can install it by using the following command :
npm install MODULE_NAME  
You can load it by using requires and used later:
 
See the Example :
var bodyParser = require('body-parser');  
app.use(bodyParser.json());  
app.use(bodyParser.urlencoded({ extended: false }))  
Note: You can use multiple middleware as an array on a single route.
See the Example :
var middlewareArray = [middleware1, middleware2]  
app.get('/home', middlewareArray, function (req, res, next) {  
  //Code snippets  
})  
Advertisement