title: nodejs convert image between buffer and string
body: <p>i want to convert png image from <code>buffer</code> to <code>string</code>, and then convert string to buffer.</p>
  
  <pre><code>fs.readFile('/Users/xxx/Desktop/1.png', (err, data) =&gt; {
      if (err) throw err; // Fail if the file can't be read.
      data = Buffer.from(data)
      let str = data.toString()
      data = Buffer.from(str)
  });
  
  // server
  router.register('/api/dump', (request, response) =&gt; { 
      fs.readFile('/Users/xxx/Desktop/1.png', (err, data) =&gt; {
          if (err) throw err; // Fail if the file can't be read. 
          response.writeHead(200, {'Content-Type': 'image/jpeg'}); 
          response.end(data); // Send the file data to the browser.
      });
  }) 
  
  // front
  this.$get('/dump').then(result =&gt; {
      // i want to convert result to buffer
  })
  </code></pre>
  
  <p>but the new buffer is not old buffer any more.</p>