title: How to convert a byte array to image in Node.js?
body: <p>How do I convert a byte array to an image in Node.js? I have tried the code below. It creates an image but when I open it, I get an error message</p>
  
  <blockquote>
    <p>Error interpreting JPEG image file.</p>
  </blockquote>
  
  <p>I have converted the byte array from bitmap in Android and sent it to a Node server.</p>
  
  <pre><code>var mkdirp = require('mkdirp');
  
  var fs = require('fs');
  
  var bitmap = new Buffer(bytearray,'base64');
  
  mkdirp(__dirname + "/images/",function(er)
  {
  
    if(er) console.log(er);
  
    fs.writeFileSync(__dirname + "/images/"+profile._id+".jpeg",bitmap);
  
  });
  </code></pre>