Categories
JavaScript Answers

How to send image files as API response with Node Express?

Spread the love

To send image files as API response with Node Express, we call res.sendFile.

For instance, we write

app.get("/report/:chart_id/:user_id", (req, res) => {
  //...
  res.sendFile(filePath);
});

to call res.sendFile with the filePath to return the image at the filePath as the response.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *