61

How do I find the a referring sites URL in node?

I'm using express, would I find this in the headers on connect or something?

Thanks!

fancy
  • 48,619
  • 62
  • 153
  • 231

2 Answers2

132

In express 4.x:

req.get('Referrer')

This will also check both spellings of referrer so you do not have to do:

 req.headers.referrer || req.headers.referer

Here is the documentation

scipilot
  • 6,681
  • 1
  • 46
  • 65
Ross
  • 14,266
  • 12
  • 60
  • 91
  • HTTP specs's header name is `Referer` and I find `req.get('Referrer')` and `req.get('Referer')` get the same result – CDT Jan 20 '22 at 02:16
76

If you mean how do you get it when running an express server, then it's done using the header method on your request:

req.headers.referer;
// => "http://google.com"
emboss
  • 38,880
  • 7
  • 101
  • 108