title: How to write a base64 video to file in nodejs
body: <p>My Express app is receiving a base64-encoded MP4 from the browser and writing it to a file. But the file isn't a valid video file, and the "file" utility simply identifies it as "data".</p>
  
  <p>My Code:</p>
  
  <pre><code>const path = `${config.uploadPath}`;
  const filename = `${uniqid()}.mp4`;
  
  let base64Data = req.body.base64.replace(/^data:([A-Za-z-+/]+);base64,/, '');
  
  
  fs.writeFileSync(`${path}${filename}`, base64Data, 'base64');
  </code></pre>