0

How does one make a call in JS to get only the header details for a remote asset? I would like to check the size of the image before deciding to use it

I'm looking for a JS equivalent of:

curl -s --head 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png'
sisanared
  • 4,175
  • 2
  • 27
  • 42

2 Answers2

3

First, pick an HTTP client library. Then use the HEAD method.

e.g.

const head_request_promise = axios({
  method: 'head',
  url: '/user/12345',
});
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

this question was asked here also

If you want to use request :

var request = require('request');

request("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png", {method: 'HEAD'}, function (err, res, body){
  console.log(res.headers);
});

If you want to use node-fetch:

const fetch = require('node-fetch');

fetch('https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png')
.then(res => console.log(res.headers.raw()))
Dabees
  • 494
  • 4
  • 14