In Express.js, req.acceptsEncodings() checks the request’s Accept-Encoding header and returns the first encoding you offered that the client accepts — for example 'gzip' or 'br'. If none match, it returns false.
It only negotiates the name. You (or compression middleware) must still compress the body and set Content-Encoding. Unlike Accept-Charset, browsers still send Accept-Encoding routinely.
Syntax
Call req.acceptsEncodings in your Express.js app. Start with this line.
Accept-Encoding: gzip, deflate
→ acceptsEncodings(['br', 'gzip']) → "gzip"
→ set Content-Encoding: gzip (after real compression)
Accept-Encoding: identity
→ false from br/gzip offer → || 'identity'
→ send uncompressed JSON
How It Works
Pass an array. Same idea as multiple arguments.
Use || 'identity'. Covers false with an uncompressed response.
Set the header only when compressed. Uncompressed responses omit Content-Encoding or use identity semantics.
Compression is separate. Libraries such as compression middleware automate this pipeline for many apps.
Compatibility
Runtime Support
req.acceptsEncodings() is an Express.js request method. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers only send Accept-Encoding.
✓ Server · Express 4 & 5
req.acceptsEncodings()
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.acceptsEncodings()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 Accept-Encoding header and returns the first encoding you offered that the client accepts (for example gzip). If none match, it returns false.
The singular alias req.acceptsEncoding() is deprecated since Express 4.5.0. Use the plural req.acceptsEncodings() instead.
Usually send the body uncompressed (identity). Prefer that over 406 for encoding negotiation in typical APIs.
No. It only chooses an encoding name. You still need compression code or middleware to actually gzip or brotli the bytes and set Content-Encoding.
No. It runs on your Node.js server. Browsers only send Accept-Encoding on the request.