In Express.js, req.acceptsLanguages() checks the request’s Accept-Language header and returns the best language your app offers. Pass one or more language tags; you get the preferred match, or false if none fit.
Call it with no arguments to get every language from the header as an array (sorted by client preference). It runs on the server via the request object — browsers only send the header.
Syntax
Call req.acceptsLanguages in your Express.js app. Start with this line.
Required. One or more language tags to test (for example 'en', 'fr', 'en-US'). Omit to list all accepted languages.
String
Required. Best match among the languages you passed
false
Required. You passed languages, but none are acceptable
String[]
Required. Called with no arguments — all languages from Accept-Language
Return Value
With arguments, req.acceptsLanguages(...) returns a matching language string or false. With no arguments, it returns an array of languages from the Accept-Language header.
Express
const lang = req.acceptsLanguages('en', 'es') || 'en';
const all = req.acceptsLanguages(); // array from the header
Express.js Examples
Example 1 — Pick the Best Language
Offer English, Spanish, and French. Return the best match from Accept-Language.
Express
const express = require('express');
const app = express();
app.get('/welcome', (req, res) => {
// Accept-Language: en;q=0.8, es → 'es'
const lang = req.acceptsLanguages('en', 'es', 'fr');
if (!lang) {
return res.status(406).send('No supported language');
}
res.json({ language: lang });
});
app.listen(3000);
Skip the language list. No arguments means “parse the header only.”
Get an array. Tags come back ordered by preference (higher q first).
Useful for debugging. Log or return the list before you narrow to supported locales.
Still not a translation API. You decide which tags your app can actually fulfill.
Example 3 — Default Locale Fallback
Prefer a match from your supported set; otherwise fall back to English instead of failing hard.
Express
const express = require('express');
const app = express();
const SUPPORTED = ['en', 'de', 'fr'];
app.get('/docs', (req, res) => {
const lang = req.acceptsLanguages(SUPPORTED) || 'en';
const copy = {
en: 'Welcome to the docs',
de: 'Willkommen in der Dokumentation',
fr: 'Bienvenue dans la documentation'
};
res.json({ language: lang, message: copy[lang] });
});
app.listen(3000);
Output
Accept-Language: ja
→ req.acceptsLanguages(['en', 'de', 'fr']) → false
→ fallback 'en'
→ 200 { "language": "en", "message": "Welcome to the docs" }
Accept-Language: de, en;q=0.5
→ "de"
→ 200 { "language": "de", "message": "Willkommen in der Dokumentation" }
How It Works
Pass an array.req.acceptsLanguages(SUPPORTED) is the same as listing each tag as an argument.
Handle false.|| 'en' picks a safe default when the client wants only unsupported languages.
Map tag → content. A small dictionary keeps the demo clear; real apps use i18n files.
Return both tag and message. The client sees which locale won and the localized string.
Compatibility
Runtime Support
req.acceptsLanguages() is an Express.js request method. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers only send the Accept-Language header.
✓ Server · Express 4 & 5
req.acceptsLanguages()
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.acceptsLanguages()Express on Node.js
Bottom line: Study and run these examples with Node.js and the express package. Prefer the plural method name on Express 4 and 5.
Frequently Asked Questions
It negotiates the best match between languages your app supports and the client's Accept-Language header. With no arguments, it returns every language from that header as an array.
When you pass language arguments and none are acceptable, it returns false. Use a default locale or send 406 Not Acceptable.
Yes. Then it returns all languages from Accept-Language as an array, ordered by client preference (quality values).
No for new code. It was deprecated in Express 4.5.0 and removed in Express 5. Always use the plural req.acceptsLanguages().
No. It only picks a language tag. Translation files, formatting, and plural rules still need your i18n stack.