Complete the code to add middleware that runs only for POST requests.
app.use((req, res, next) => {
if (req.method === '[1]') {
console.log('POST request detected');
}
next();
});The middleware checks if the request method is 'POST' to run the code only for POST requests.
Complete the code to apply middleware only on routes starting with '/admin'.
app.use('[1]', (req, res, next) => { console.log('Admin route accessed'); next(); });
Middleware with path '/admin' runs only on routes that start with '/admin'.
Fix the error in the middleware to run only if query parameter 'debug' equals 'true'.
app.use((req, res, next) => {
if (req.query.debug [1] 'true') {
console.log('Debug mode active');
}
next();
});Use '===' for strict equality check in JavaScript to compare query parameter to string 'true'.
Fill both blanks to create middleware that runs only for PUT requests on '/update' path.
app.[1]('/update', (req, res, next) => { if (req.method === '[2]') { console.log('Update request received'); } next(); });
Use app.put() to handle PUT requests on '/update' path and check method 'PUT' inside middleware.
Fill all three blanks to create middleware that runs only if the user is authenticated and the request method is DELETE on '/remove' path.
app.[1]('/remove', (req, res, next) => { if (req.user && req.method === '[2]') { console.log('Authenticated DELETE request'); [3](); } else { res.status(403).send('Forbidden'); } });
Use app.delete() for DELETE requests on '/remove'. Check req.method === 'DELETE'. Call next() to continue middleware chain.