title: Cannot save a remote image with node.js and request
body: <p>I want to save an image with node.js and the <a href="https://github.com/request/request" rel="noreferrer">request library</a>. So far I have this simple code:</p>
  
  <pre><code>var request = require('request');
  var fs = require('fs');
  
  request('http://upload.wikimedia.org/wikipedia/commons/8/8c/JPEG_example_JPG_RIP_025.jpg', function(error, response, body)
  {
      // further logic that decides
      // whether or not the image will be saved
  
      fs.writeFile('downloaded.jpg', body, function(){});
  });
  </code></pre>
  
  <p>But it doesn't work. The image always arrives corrupt. I assume it's an encoding error but I cannot figure out how to fix this.</p>