Downloading image doesn't work: NodeJS
<p>I've written a little function in Node for downloading an image from a server and saving it on my server, but it doesn't work. The image file is created, but it seems to be corrupt, here's the function: </p>

<pre><code>function d() {
    var data = [
        {
            img: "http://wow.zamimg.com/images/hearthstone/cards/enus/original/OG_134.png",
            cardId: "yogg"
        },
        {
            img: "http://wow.zamimg.com/images/hearthstone/cards/enus/original/HERO_07.png",
            cardId: "nzoth"
        }
    ];
    for(var card of data) {
        if("img" in card) {
            var img = require('fs').createWriteStream("./public/assets/pics/" + card.cardId + ".png");
            require("http").get(card.img, (res) =&gt; {
                res.pipe(img);
            });
        }
    }
}
</code></pre>

<p>What am I doing wrong?</p>