title: Convert "Buffer 64 61 74 61 3a 69 6d 61 67 65 2f" to img src in react
body: <p>I am working on retrieving the image data url from postgresql database and convert back to img src in react. However the below code is not work and the base64 string is kind of strange when console log.</p>
  <pre><code>const bufs = Buffer.from(returnUser[0].img);
  const base64 = bufs.toString(&quot;base64&quot;);
  res.json({
        userName: returnUser[0].username,
        id: returnUser[0].id,
        userImg: `data:image/jpeg;base64,${base64}`,
  });
  </code></pre>
  <ol>
  <li><p>In nodejs, the data I got back from database <code>returnUser[0].img</code> is like <code>&lt;Buffer 64 61 74 61 3a 69 6d 61 67 65 2f 6a 70 65 67 3b 62 61 73 65 36 34 2c 2f 39 6a 2f 34 41 41 51 53 6b 5a 4a 52 67 41 42 41 51 45 41 53 41 42 49 41 41 44 ... 67141 more bytes&gt; </code></p>
  </li>
  <li><p>I console the <code>base64</code> is like <code>ZGF0YTppbWFnZS9qcGVnO2Jhc2U2NCwvOWovNEF...</code> Then I copy all the <code>base64 stuff</code> to the online decode website. <a href="https://base64.guru/converter/decode/file" rel="nofollow noreferrer">https://base64.guru/converter/decode/file</a>. The result coming back is what I want: <code>data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2NjIpLCBxdWFsaXR5ID0gOTIK/9sAQwAG... </code></p>
  </li>
  <li><p>The above result I copy to the react image, it works.</p>
  </li>
  </ol>
  <p>But I don't know how I can get this result in nodejs. Are there any code I am missing?
  <code>data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBG... </code></p>
  <p>Thanks so much for the answers!</p>