title: Decode Base64 string in node.js
body: <p>I'm trying to decode a base64 string representing an image stored in a db. 
  I tried many libraries and solutions provided on SO, but I'm still unable to decode the image correctly. In particular, using the following code: </p>
  
  <pre><code>var img = new Buffer(b64, 'base64').toString('ascii');
  </code></pre>
  
  <p>I get a similar binary representation, except for the first bytes. 
  This is the initial part of the base64 string: </p>
  
  <pre><code>/9j/4RxVRXhpZgAASUkqAAgAAAANADIBAgAUAAAAqgAAACWIBAABAAAAiwYAABABAgAIAAAAvgAA
  </code></pre>
  
  <p>Here are the first 50 bytes of the original image:</p>
  
  <pre><code>ffd8ffe11c5545786966000049492a00080000000d003201020014000000aa00000025880400010000008b06000010010200
  </code></pre>
  
  <p>And here are the first 50 bytes of the string I get with javascript:</p>
  
  <pre><code>7f587f611c5545786966000049492a00080000000d0032010200140000002a00000025080400010000000b06000010010200
  </code></pre>
  
  <p>How you can see, the two strings are identical except for the fisrt 3 bytes and some few bytes in the middle.<br>
  Can somebody help me understand why this is happening and how to solve it? Thanks</p>