1
I had asked a question here yesterday, and the 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 that is not an image (and is at http) the following error is displayed:
if (!(fileType(chunk).ext == "png")) {
^
TypeError: Cannot read property 'ext' of null
Could someone help me? Thanks in advance.
But it’s general, isn’t it? I just want it not to Return when it’s not a PNG.
– Gabriel
@Gabriel You can use the
if
only to prevent it from making a mistake - but you can continue with the program instead of givingreturn
.– Daniel
@Gabriel Please see my issue in reply (I tried to leave complete).
– Daniel