How can I get the browser language in node.js (express.js)?

User requests some page and I want to know (on server side) what is the language in his/her browser. So I could render template with the right messages.

On client side it's easy:

var language = window.navigator.userLanguage || window.navigator.language

You can use req.headers["accept-language"] to get the language/locale the user has set in his browser.

For easier support, you may want to look into a locale module.


request.acceptsLanguages will contain a parsed version of request.headers['accept-language'].

See: http://expressjs.com/en/api.html#req.acceptsLanguages