QA
Beginner LevelExpress JS

How do you inspect the incoming HTTP verb using req.method?

❓ Interview Prompt: Explain req.method inspection, uppercase HTTP verb strings, and writing custom HTTP verb logging middleware.

'req.method' returns an uppercase string representing the HTTP request method sent by the client (e.g. '"GET"', '"POST"', '"PUT"', '"DELETE"', '"OPTIONS"'). Used extensively in logging and audit trail middleware.

Code Implementation Example

javascript
import express from 'express';
const app = express();

app.use((req, res, next) => {
  // Inspect uppercase HTTP verb
  if (req.method === 'POST' || req.method === 'PUT') {
    console.log(`Data mutation attempt detected via ${req.method}`);
  }
  next();
});
💡Inspecting incoming HTTP verb strings using req.method.
🎯 Interview Key Takeaway

req.method returns uppercase HTTP verb strings ("GET", "POST") used for audit logging and route filtering.

#req.method#HTTP Verbs#Beginner
Back to all Express JS Questions→

More Express JS Interview Questions

Beginner LevelExpress JS

What is Express.js and how does the middleware pipeline work?

Beginner LevelExpress JS

What is the difference between req.params, req.query, and req.body?

Beginner LevelExpress JS

How does express.Router() work for building modular route controllers?