kmonsoor
kmonsoor

Reputation: 8119

SuperAgent -- Fetching only the headers

I am using superagent from Node.

For a simple request like this, how can I fetch/request only the headers of the page, not the full-content ?

request.get('https://google.com') .then((res) => {console.log(res.headers);}) .catch(err=> console.log(err.status));

I tried to find in the documentation and Google but couldn't find anything on it.

Upvotes: 0

Views: 986

Answers (1)

kmonsoor
kmonsoor

Reputation: 8119

Thanks to @CBroe for pointing me to the right direction.

For the visitors from the future ...

What you need is to replace GET request with HEAD request.
For example, in my case, it would be:

const request = require('superagent');

request
  .head('https://google.com')
  .then((res) => {console.log(res.headers);})
  .catch(err=> console.log(err.status));

Upvotes: 1

Related Questions