Complete the code to define a middleware function that logs the request method.
app.use(function(req, res, [1]) {
console.log(req.method);
next();
});send or end instead of next causes the request to stop.The next function is used to pass control to the next middleware.
Complete the code to call the next middleware after logging the URL.
app.use((req, res, [1]) => { console.log(req.url); [1](); });
next() causes the request to hang.Calling next() passes control to the next middleware in the stack.
Fix the error in the middleware to properly pass control to the next function.
app.use(function(req, res, next) {
console.log('Middleware running');
[1]();
});next; instead of next(); does not call the function.You must call next() as a function, not just reference it.
Fill both blanks to create middleware that checks if user is authenticated and calls next or sends 401.
app.use(function(req, res, [1]) { if (!req.user) { res.status(401).[2]('Unauthorized'); } else { next(); } });
end or json instead of send for the response.The middleware uses next to continue if authenticated, otherwise sends a 401 response with send.
Fill all three blanks to create middleware that logs method, URL, and calls next.
app.use(function(req, res, [1]) { console.log(req.[2] + ' ' + req.[3]); next(); });
body instead of url for the request path.The middleware logs the HTTP method and URL, then calls next() to continue.