Complete the code to add a middleware that logs every request.
app.use([1]);The app.use() method adds middleware. Here, loggerMiddleware is the function that logs requests.
Complete the code to protect a route with authentication middleware.
app.get('/dashboard', [1], (req, res) => { res.send('Welcome!'); });
The authMiddleware checks if the user is authenticated before allowing access to the dashboard route.
Fix the error in composing two middleware functions for a route.
app.post('/submit', [1], (req, res) => { res.send('Submitted'); });
To use multiple middleware functions for a route, pass them as an array or as separate arguments. Here, an array is correct syntax inside the single blank.
Fill both blanks to create a middleware chain that first authenticates, then logs the request.
app.use([1], [2]);
The middleware chain runs in order: first authMiddleware to check authentication, then loggerMiddleware to log the request.
Fill all three blanks to create a route with JSON parsing, authentication, and logging middleware.
app.post('/api/data', [1], [2], [3], (req, res) => { res.json({ success: true }); });
The route uses express.json() to parse JSON body, then authMiddleware to check user, and finally loggerMiddleware to log the request.