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

Some times, We need to get Referer http header in Node application. This post explains about how to find the referer url in Nodejs applicaiton. This tutorial describes all the steps to retrieve referer in javascript

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

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

In request header, You will see the following value


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

How to find the referer page url in nodeJS application

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

if you are using express version less than 4.x

You can directly call below method

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

In expression 4.x version

you can get using request.get method

Referrer is an case insensitive header

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

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


You learned how to retrieved return url in node express application. This header value is controlled by client, This can be modified and changed to different value, So it is not better to use logic based on value. However logging and analytics purpose we can consider

Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
You'll get a notification every time a post gets published here.