Search code examples
node.jsrequestnavigator

Does the request object in Node.js contain any navigator.userAgent type of information?


I've setup a Node.js server that gets some contact form data and forwards it to my email. I'd like to be able to forward some information about the user's browser along with the form data.

Is any of that information contained in the request object in some form ? Kind of like the navigator.userAgent string that is available on the client ?

Or should I include that string in the data sent out, manually, myself?

I was thinking of something like :

var httpServer = http.createServer(function (request, response)
{
   var browserID = request.navigator.userAgent;
});

Thanks!


Solution

  • I was testing this out myself in express, and you can find the user-agent string in:

    request.header['user-agent']
    

    and you can see it in the HTTP specification in 14.43 here.


    In the future, you can simply examine the request object either with console.log() or with the debugger and see exactly what's in it. I find that is often ultimately more educational than trying to find things in documentation somewhere.