Can you try requesting a bigger file? With 2 characters I guess it's possible that the connection would have already closed by the time the main function was called. I know I deal with that for the data handler, but maybe not the close handler.
To work around it, you could do:
var req = require('http').request(options, function(res) {
console.log(res);
var l = res.headers["Content-Length"];
res.on('data', function(data) {
contents += data;
if (contents.length>=l) console.log("Do stuff now");
});
});
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Can you try requesting a bigger file? With 2 characters I guess it's possible that the connection would have already closed by the time the main function was called. I know I deal with that for the data handler, but maybe not the
close
handler.To work around it, you could do: