Có thể tạo ra các middleware có khả năng cấu hình linh hoạt như sau:

// superMiddleware.js
module.exports = function (options) {
	return function (req, res, next) {
		// Implement the middleware function based on the options object
		next()
	}
}

Chúng ta có thể cấu hình middleware thông qua tham số options:

// index.js
const superMiddleware = require('./superMiddleware.js')
 
app.use(superMiddleware({ option1: '1', option2: '2' }))