Express.js req.method Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Request

Definition

In Express.js, req.method is a string with the HTTP method of the current request — GET, POST, PUT, DELETE, and so on.

Read it in middleware or shared handlers (for example with app.all()) to log, audit, or branch. Prefer dedicated routes like app.get() / app.post() for most endpoints; use req.method when one stack must react to the verb.

Syntax

Read req.method in your Express.js route handler. Start with this line.

Express
req.method
CallWhat it does
req.methodPrimary signature.

Install with npm install express. Create the app with const app = express() before you use this API in an Express.js tutorial project.

Library declarations
Express
const express = require("express");
const app = express();

req.method

Parameters

This Express.js property is read from the request or response — it has no call parameters.

Return Value

req.method is an uppercase string property such as 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', or 'OPTIONS'.

Express
if (req.method === 'POST') {
  // handle create
}
// req.method === 'get' is always false

Express.js Examples

Example 1 — Log Method in Middleware

Print the verb and URL for every request, matching the official middleware pattern.

Express
const express = require('express');
const app = express();

app.use((req, res, next) => {
  console.log('Request Type:', req.method);
  console.dir(req.method); // => 'GET'
  next();
});

app.get('/', (req, res) => {
  res.send('Home');
});

app.listen(3000);

How It Works

  1. Middleware runs first. app.use sees every request before routes.
  2. Read the property. req.method is the uppercase verb string.
  3. Call next(). Logging must not stop the chain.
  4. Route answers. app.get('/') sends the body after the log line.

Example 2 — Branch Inside app.all

One path, several verbs: decide the reply from req.method.

Express
const express = require('express');
const app = express();

app.all('/resource', (req, res) => {
  if (req.method === 'GET') {
    return res.send('Read resource');
  }
  if (req.method === 'POST') {
    return res.send('Create resource');
  }
  res.status(405).send('Method Not Allowed');
});

app.listen(3000);

How It Works

  1. Match every verb. app.all('/resource') runs for GET, POST, DELETE, …
  2. Compare uppercase strings. === 'GET' / === 'POST' select the branch.
  3. Return after sending. Stops further checks once a response is sent.
  4. Fallback to 405. Anything else is not allowed on this path.

Example 3 — Allow-List with 405 and Allow

Reject unknown verbs explicitly and advertise what is allowed.

Express
const express = require('express');
const app = express();

const allowed = new Set(['GET', 'POST']);

app.all('/items', (req, res) => {
  if (!allowed.has(req.method)) {
    res.set('Allow', 'GET, POST');
    return res.status(405).send('Method Not Allowed');
  }
  res.send(req.method + ' /items OK');
});

app.listen(3000);

How It Works

  1. Keep an allow-list. Only listed verbs continue.
  2. Check req.method. Unknown verbs fail the Set test.
  3. Set Allow. Clients learn which methods are valid.
  4. Send 405. Correct status for “path exists, verb does not.”

Runtime Support

req.method is an Express.js request property (backed by Node’s HTTP request). It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers do not execute it — they only send the HTTP method to your app.

✓ Server · Express 4 & 5

req.method

Works wherever Express runs: Node.js is the primary target. Bun and Deno can run many Express apps with compatibility layers. Not available in the browser.

Server Node.js runtime API
Node.js 18+ for Express 5 · 14+ typical for Express 4
Supported
Bun Express-compatible server apps
Supported
Deno Via npm compatibility / adapters
Supported
req.method Express on Node.js

Bottom line: Study and run these examples with Node.js and the express package. Copy a snippet into a local file and start the server with node.

Frequently Asked Questions

It is a string with the HTTP method of the current request, such as GET, POST, PUT, PATCH, or DELETE.
Yes in normal Node.js/Express handling. Compare with uppercase literals like 'GET' and 'POST'.
Use it in shared middleware for logging, audits, or branching when one handler covers several verbs (for example with app.all).
app.get() registers a route that only runs for GET. req.method tells you which verb the incoming request actually used.
No. It is a server-side request property. Browsers send the HTTP method; Express exposes it as req.method on the server.

Next: req.originalUrl

Keep the full original request URL even when middleware rewrites req.url.

req.originalUrl tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful