title: NodeJs: Sending picture with Express (Multer)
body: <p>I have this code</p>
  
  <pre><code>app.get('/imgs/:id', function(req, res) {
      // Validate that req.params.id is 16 bytes hex string
      // Get the stored image type for this image
      var stream = fs.createReadStream(path.join(UPLOAD_PATH, req.params.id));
      stream.on("readable", function() {
          res.setHeader('Content-Type', "image/jpeg")
          stream.pipe(res)
      })
      stream.on('error', (e) =&gt; {
          res.redirect(404, "404")
      })
  });
  </code></pre>
  
  <p>Now the problem is that I always get an error of </p>
  
  <blockquote>
    <p>Error: Can't set headers after they are sent.</p>
  </blockquote>
  
  <p>because I used the <code>res.setHeader</code> function.
  However, i don't know how to solve it. Let's say I want to use in a page, that has obviously the <code>res.send()</code> function has well,
  the <code>&lt;img src="imgs/pic"&gt;</code>, then I must set the header for the this page request to <code>"image/jpeg"</code> because otherwise the browser wouldn't know it's an image and won't show it as one.</p>
  
  <p>What can I do then?</p>