title: Convert base64 image to a file in Node Js
body: <p>I am new to Node Js. I need to include a profile image for users. I get request of image in base64 from IOS app. I need to store it in images folder and save the image path in mongodb database.</p>
  
  <p>I have used the following code,</p>
  
  <pre><code>var bitmap = new Buffer(req.body.profile_image, 'base64');
  // write buffer to file
  fs.writeFileSync("images/example.jpg", bitmap);
  </code></pre>
  
  <p>where req.body.profile_image is a base64 image.</p>
  
  <p>I am getting the following error,</p>
  
  <pre><code>TypeError: First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.
  </code></pre>
  
  <p>req.body.profile_image value will be,</p>
  
  <pre><code>+MZScHeJQ9Cz5dfxnEmIMHWMZyZYnYx8Rrhj0HbtfGUanv5w3UHUyADbiGsKJxeM1yV4uGwBS7cYlAec1w0AX6xg2A1O854UF8OS6PAP1MtzkeFnrNlD41U8XFeGrp1fn3jRMUs8sqS61umSS2rR2NDhppjZ4OvnOWBAq6X+sQNkhKkfZOdYsZOpz8fWIQb6wQ/GchVCgfZko4PMDg1DSumausG6o+2E6wKLLjKReUaHEQXKJV8h85XEKN4p/WEBvTHmmJ/IN178YJVgrGmfOScAuBPp+sggGA7/wC1kgbDiacbGABOcCLHVRpMuBQh5Xn4xqARF03pwkJT23LhxGLiSGp8mCVWDrzPf3iwp4C3nDSg2VUfNwgDvm6vrIiFJvp8ZHIdjoFx8BX0OH0+8TVii3GAKKc2kjz7dYqUCdsuMOm2hrr+h//Z
  </code></pre>
  
  <p>Please help.</p>