Can't download files using nodejs



I have this code in one of my projects. The problem is that it isn’t downloading any file, don’t get me wrong, it works in my own pc but in my workspace isn’t working, I wonder if I’m not allowed to download or something like that. I would really appreciate any help.

function downloadFile(url, dest, cb) {
    // first check if file doesn't already exist
    fs.stat(dest, function (err, stat) {
        if (!(err == null) && err.code === 'ENOENT') {
            var file = fs.createWriteStream(dest);
            https.request(url, function (response) {
                file.on('finish', function () {
            }).on('error', function (err) {
                if (cb) {
                } else {


There is nothing in cloud9 setup that could block the above code snippet.
Check the url and add some more console.log calls to see why it fails.
You can also use the built in nodejs debugger


alright, I still wonder why it fails in cloud9 but it doesn’t in my pc :confused:
I will try to do what you said, will updated if something failed…


Ok, I think I know where the problem is… I’m getting 2 completely different html content in c9 and in my pc, how is this even possible???
Do c9 send some kind of headers or something? weird I must say :'c
Well then, If this continues I guess I will have to make a branch only for cloud9


c9 doesn’t modify contents of downloaded files, from what url are you trying to download?