In Express.js, req.accepts() checks the request’s Accept header and returns the best match from the types you can produce. Pass extensions like 'json' / 'html' or full MIME types like 'application/json'.
If nothing matches, it returns false — then you should usually send 406 Not Acceptable (or use a deliberate fallback). It runs inside your Express request handler on the server; browsers only send the Accept header.
Syntax
Call req.accepts in your Express.js app. Start with this line.
Express
req.accepts(types)
req.accepts(type1, type2, ...)
Call
What it does
req.accepts(types)
Primary signature.
req.accepts(type1, type2, ...)
Related call form.
Install with npm install express. Create the app with const app = express() before you use this API in an Express.js tutorial project.
GET /report Accept: image/png
→ req.accepts('json', 'html') → false
→ 406 Not Acceptable
GET /report Accept: application/json
→ "json" → { "ok": true }
How It Works
Pass types as arguments.req.accepts('json', 'html') is the same idea as an array.
Check for false. Official docs recommend 406 when nothing matches.
Only then send a body. Matching clients get JSON or HTML as usual.
Raw header is different.req.get('Accept') returns the header text; req.accepts does the matching.
Compatibility
Runtime Support
req.accepts() is an Express.js request method. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers only send the Accept header.
✓ Server · Express 4 & 5
req.accepts()
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.accepts()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 reads the request Accept header and returns the best match from the types you offer (extensions like json or full MIME types). If nothing matches, it returns false.
Respond with 406 Not Acceptable, or fall back to a default format if your API allows it.
A single type, several arguments (req.accepts('html', 'json')), or an array (req.accepts(['html', 'json'])). Extensions and full MIME types both work.
req.accepts() only picks the best type string. res.format() uses that negotiation and runs a handler map for each type (and can send 406 automatically).
No. It runs on your Node.js server. Browsers only send the Accept header on the HTTP request.