title: In Node.js, given a URL, how do I check whether its a jpg/png/gif?
body: <p>My current method is this:</p>
  
  <pre><code>var request = require('request');
  var mime = require('mime');
  var fs = require('fs');
  var uri = 'http://www.sweetslyrics.com/images/img_gal/25646_christina-perri-213968.jpg';
  request({
          'method':'GET',
          'uri': uri
  },function(err, response,body){
      var tmp_path = '/tmp/123456';
      fs.writeFile(tmp_path, body, function(err) {
          console.log(mime.lookup(tmp_path));  //application/octet-stream ?????
      });
  });
  </code></pre>
  
  <p>The image is obviously a picture, but <code>node-mime</code> says it's <code>application/octet-stream</code>. Why?</p>
  
  <p>Note: 
  - I do not want to rely on the Response Headers content-type, because based on my experience, sometimes those response headers are set incorrectly...and they do not determine the true file type. (that's why I save it to a file, and then have node-mime determine it for me!)</p>
  
  <p><strong>I want to know the best way to determine if a file is an image, with 0 margin of error.</strong></p>
  
  <p>Edit: I just realized that node-mime isn't "magic".  It just checks for the extension :( ...</p>
  
  <p>Edit2: I found this: <a href="https://github.com/SaltwaterC/mime-magic" rel="noreferrer">https://github.com/SaltwaterC/mime-magic</a></p>