How to detect browser / User-Agent in Node.js#

Whether you are using a bare bones Node.js HTTP server or Express, the browser user agent information can be found in the User-Agent HTTP request header.

The request object is popularly named req, so the user agent information can be found at req.headers['user-agent'].

With many browsers and versions, browser detection is a very nuanced task. If you are looking for fine control about the details you detect, you should use the ua-parser module.

Like all HTTP headers, the User-Agent header can be easily faked.


  1. MDN - HTTP Headers
  2. Node.js - HTTP request object
  3. Node.js - HTTP request headers
Tweet this | Share on LinkedIn |