In Express.js, req.is() checks whether the request’s Content-Type matches a MIME type or shorthand you pass. On a match it returns that type string; otherwise false. If the request has no body, it returns null.
Use it before reading req.body to enforce JSON or form payloads. It is powered by the type-is library. For what the client wants in the response, use req.accepts() instead.
Syntax
Call req.is in your Express.js app. Start with this line.
Required. MIME type (application/json), extension shorthand (json, html), wildcard (text/*), comma list, or array.
String
Required. Header matches — value is the type you asked for that matched (for example 'json' or 'text/*')
false
Required. Body present, but no listed type matches
null
Required. Request has no body (common on GET)
Return Value
req.is(type) returns the first matching type string you passed (for example 'json'), or a falsy value (false/null) when there is no match or no body type to test.
Express
if (!req.is('json')) {
return res.status(415).send('JSON only');
}
// match may be the string 'json', not boolean true
Express.js Examples
Example 1 — Require a JSON Body
Reject non-JSON posts with 415 before handling the payload.
POST /notes Content-Type: text/html; charset=utf-8
→ Matched: text/*
POST /notes Content-Type: text/plain
→ Matched: text/*
POST /notes Content-Type: application/json
→ 415 text/* required
How It Works
Wildcards widen the match.text/* covers text/html, text/plain, and similar.
Parameters are ignored for the check.charset=utf-8 does not block a match.
Return echoes the pattern. On success you get 'text/*' (the type you tested).
Non-text types fail. JSON returns false → 415.
Compatibility
Runtime Support
req.is() is an Express.js request method. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers do not execute it — they only send HTTP requests to your app.
✓ Server · Express 4 & 5
req.is()
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.
ServerNode.js runtime API
Node.js18+ for Express 5 · 14+ typical for Express 4
Supported
BunExpress-compatible server apps
Supported
DenoVia npm compatibility / adapters
Supported
req.is()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 checks the request Content-Type header against one or more MIME types or shorthand names (like json or html) and returns the match, false, or null.
A matching type string (for example 'json' or 'text/html'), false when nothing matches, or null when the request has no body.
req.is() inspects the incoming Content-Type (what the client sent). req.accepts() inspects the Accept header (what the client wants back).
Yes. Pass multiple arguments or an array, such as req.is('json', 'urlencoded') or req.is(['json', 'html']). The first match wins.
No. It is a server-side Express request method. Browsers only send HTTP requests; your Node.js app calls req.is().