Complete the code to log the HTTP method of the request.
app.use((req, res) => {
console.log(req.[1]);
res.end();
});The req.method property contains the HTTP method (GET, POST, etc.) of the request.
Complete the code to log the URL path of the request.
app.use((req, res) => {
console.log(req.[1]);
res.end();
});The req.url property contains the URL path and query string of the request.
Fix the error in the code to correctly check if the request method is POST.
app.use((req, res) => {
if (req.[1] === 'POST') {
res.end('Got a POST request');
} else {
res.end('Not a POST request');
}
});To check the HTTP method, use req.method. Comparing req.url or others will not work.
Fill both blanks to log the method and URL of the request.
app.use((req, res) => {
console.log('Method:', req.[1]);
console.log('URL:', req.[2]);
res.end();
});Use req.method for the HTTP method and req.url for the URL path.
Fill all three blanks to respond differently based on method and log the URL.
app.use((req, res) => {
if (req.[1] === 'GET') {
res.end('GET request received');
} else if (req.[2] === 'POST') {
res.end('POST request received');
} else {
res.end('Other request');
}
console.log('URL:', req.[3]);
});Check req.method for the HTTP method in both conditions and log req.url for the URL.
