Download image with node-request

Hey I am a real beginner with node js so bear with me. I am trying to download a file ( an image) this is the code I have :

function downloadFileFromURL( url, callback ) 
{
    file_name = path.basename(url);

    var wstream = fs.createWriteStream(file_name);

    wstream.on('error', function (err) {
        console.log(err, url);
    });

    wstream.on( 'close', function(){

        console.log( "finished downloading: ", url, this.path );

    });

    request(img_url).pipe( wstream );
}

if I parse a blog feed with my app, this function downloads about half of the images. I can see the images fine from a browser. The files get created but some of them stay at 0 bytes.

the example feed I am parsing is: http://feeds.feedburner.com/ButDoesItFloat?format=xml

I saw this question on here: node.js Writing image to local server which is similar and would love to see how its done with node-request

Take a look at http-get to achives it. You just need to pass two parameters, first, the URL, the second is the path where the file will be saved, pretty simple. The callback function returns the filename as "result.file". Check the code below and give a try:

var http = require('http-get');
http.get('www.ohmydear.com/thesite.png', '/path/to/thesite.png', function (error, result) {
    if (error) {
        console.error(error);
    } else {
        console.log('File downloaded at: ' + result.file);
    }
});