To get HTTP headers with Node.js, we use the headers
property.
For instance, we write
const http = require("http");
const options = { method: "HEAD", host: "example.com", port: 80, path: "/" };
const req = http.request(options, (res) => {
console.log(JSON.stringify(res.headers));
});
req.end();
to call http.request
with the options
to make a get request.
And we get the response headers with res.headers
in the callback.