Detecting AJAX requests on NodeJS with Express

ajax, express, node.js

Solution

Most frameworks set the `X-Requested-With` header to `XMLHttpRequest`, for which Express has a test:

app.get('/path', function(req, res) {
  var isAjaxRequest = req.xhr;
  ...
});

Problem

I'm using NodeJS with Express. How can I tell the difference between an ordinary browser request and an AJAX request? I know I could check the request headers but does Node/Exprsss expose this information?

Original source