Express req.acceptsLanguages() Method

Beginner
⏱️ 8 min read
📚 Updated: May 2026
🎯 4 Code Examples

What you’ll learn

  • How req.acceptsLanguages() negotiates response language.
  • How to choose language fallback when no exact match exists.
  • How this method integrates with localization workflows.
  • How to avoid common language negotiation mistakes.

Syntax

javascript
req.acceptsLanguages(lang)
req.acceptsLanguages(lang1, lang2, ...)
req.acceptsLanguages([languages])
1

Basic language negotiation

javascript
app.get('/welcome', function (req, res) {
  var lang = req.acceptsLanguages('en', 'fr', 'es') || 'en';
  res.json({ language: lang });
});
2

Fallback to default locale

javascript
app.get('/docs', function (req, res) {
  var lang = req.acceptsLanguages(['en', 'de']) || 'en';
  res.send('Docs language: ' + lang);
});

❓ FAQ

It matches supported languages against the Accept-Language header and returns the best match.
It returns false, so you can use a default language fallback.
Yes. You can pass multiple arguments or an array like req.acceptsLanguages('en', 'fr', 'es').
Yes. It helps pick a preferred locale before rendering localized content.
No. It helps with negotiation, while i18n libraries manage translations and locale formatting.
Did you know?

req.acceptsLanguages() checks the client's Accept-Language header and helps choose an appropriate response locale.

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.

4 people found this page helpful