• 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");
                });
            });
    
About

Avatar for Gordon @Gordon started