Complete the code to create a middleware factory that returns a middleware function.
function logger(level) {
return function(req, res, next) {
console.log(level + ': Request received');
[1]();
};
}The middleware factory returns a function that calls next() to pass control to the next middleware.
Complete the code to use the middleware factory with a specific log level.
const express = require('express'); const app = express(); app.use(logger([1]));
The log level should be passed as a string to the middleware factory.
Fix the error in the middleware factory to correctly handle the next function.
function logger(level) {
return function(req, res, next) {
console.log(level + ': Request received');
[1];
};
}The next function must be called with parentheses to invoke it.
Fill both blanks to create a middleware factory that logs the method and URL of requests.
function requestLogger([1]) { return function(req, res, [2]) { console.log(req.method + ' ' + req.url); next(); }; }
The factory takes a parameter level and the middleware function uses next to continue.
Fill all three blanks to create a middleware factory that adds a custom header with the given name and value.
function headerSetter([1], [2]) { return function(req, res, [3]) { res.setHeader([1], [2]); next(); }; }
The factory takes headerName and headerValue. The middleware function uses next to continue.