I had asked a question here yesterday, and Blogger helped me by passing this code:
const http = require('http');
const fileType = require('file-type');
const url = 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-logo.png';
http.get(url, res => {
res.once('data', chunk => {
if (!(fileType(chunk).ext == "png")) {
console.log("deu ruim");
// aqui vem o seu return
}
res.destroy();
console.log(fileType(chunk));
});
});
But when placing a URL where it is not an image (and is in http) the following error is displayed:
if (!(fileType(chunk).ext == "png")) {
^
TypeError: Cannot read property 'ext' of null
Can anyone help me? Thanks in advance.