How to get return url in nodejs application|http referrer header example

Sometimes, We need to get the Referer HTTP header in the Node application. This post explains how to find the referer URL in the Nodejs application. This tutorial describes all the steps to retrieve referer in javascript

[Referer]( is an HTTP optional header in a request that contains a domain or a page URL making the request. some times Referer is also called referrer as old browsers still reference this. We can use any one of these.

Suppose In a, You have a link pointing to a different, and website2 contains Referer as

In the request header, You will see the following value


if you directly access the website, the referrer value is undefined.

How to find the referer page url in the nodeJS application

In Nodejs, Express library HTTP headers are retrieved using the request object.

if you are using an express version less than 4. x

You can directly call the below method

console.log(req.headers.referer) //

In expression 4. x version

you can get using request. get method

A referrer is a case-insensitive header.

console.log(req.get('Referrer')) //

This method checks for the Referer and Referrer header in a request


To Sum up,

In the node express application, you learned how to get the return URL. The client can change this header value. Because this can be changed to a different value, it is not a good idea to utilize logic based on value. However, we can consider logging and analytics purposes.