DEV Community


How do we access response headers in Javascript ?

dhanushxeno profile image DHANUSH N ・1 min read

I am setting a correlation Id in node js application & I need to access it in the frontend to pass in the request again. Not sure how to access.

Discussion (5)

Editor guide
jordanfinners profile image
Jordan Finneran • Edited

It would depend what you are using on the frontend to make the request.
If you are using the fetch API (native in all browsers except IE) you can access the response headers

I would probably look for a monitoring tool to do this for you though, like datadog or AWS Cloudwatch or Azure Applications Insights.

valeriavg profile image

What are you using in nodejs?
Built-in http server has res.setHeader, while express has res.header method for that.

ronnymedina profile image
Ronny Medina

Do you have an example of this?

dhanushxeno profile image
DHANUSH N Author • Edited

In my node server
I have did like res.set( correlationid, 12345)
I need to access the value from frontend react, response.headers in frontend not able to get the correlationid

ronnymedina profile image
Ronny Medina

Do you want to set headers on the node?, maybe this example could be used


res.set({ 'correlationid': '12345'}); 
Enter fullscreen mode Exit fullscreen mode