express image node.js

Node Express sending image files as API response

I Googled this but couldn’t find an answer but it must be a common problem. This is the same question as Node request (read image stream – pipe back to response), which is unanswered.

How do I send an image file as an Express .send() response? I need to map RESTful urls to images – but how do I send the binary file with the right headers? E.g.,

<img src="" />


app.get('/report/:chart_id/:user_id', function (req, res) {
//authenticate user_id, get chart_id obfuscated url
//send image binary with correct headers

There is an api in Express.


app.get('/report/:chart_id/:user_id', function (req, res) {
// res.sendFile(filepath);