Home > OS >  How do I read request header without Express
How do I read request header without Express

Time:07-16

Simply, I have a function that gets the weather using request library. I want to see my request header but all the topics I looked at used with Express. How can I do this ?

const request = require('request');
function getDegree(cityURL){
request.get({ 
    url:cityURL
    }, (err, res, body)=>{
    if (err) console.log(err);

//My standart codes

console.log(temps); 

//I want console.log(requestHeader) or something like this here, for example.

})
}

CodePudding user response:

You can read the request headers by storing it inside a variable (myRequest), then use myRequest.headers.

const request = require("request");

var myRequest = request.get(options, (err, res, body) => {
  console.log(requestHeaders);
});

var requestHeaders = myRequest.headers;
  • Related