Complete the code to import the Express module.
const express = require([1]);The Express module is imported by requiring the string "express".
Complete the code to create an Express app instance.
const app = [1]();require() instead of express().router().Calling express() creates a new Express application instance.
Fix the error in the middleware function to correctly call next.
function authMiddleware(req, res, next) {
if (req.user) {
[1]();
} else {
res.status(401).send('Unauthorized');
}
}next without parentheses.res.next() which does not exist.The middleware must call next() as a function to pass control to the next middleware or route handler.
Fill both blanks to protect the route with the auth middleware.
app.[1]('/dashboard', [2], (req, res) => { res.send('Welcome to your dashboard'); });
express.json() instead of auth middleware.The route uses app.get to handle GET requests, and the authMiddleware is added before the route handler to protect it.
Fill all three blanks to create and use auth middleware that checks for a token header.
function [1](req, res, next) { const token = req.headers['[2]']; if (token === 'secret') { next(); } else { res.status(403).send('Forbidden'); } } app.[3]('/protected', [1], (req, res) => { res.send('Protected content'); });
The middleware is named authMiddleware. It checks the 'x-access-token' header for the token. The route uses app.get to protect the '/protected' path.