'Can I response file Node to React

Is it possible to create a rest api responsing an image file using node? Wondering if there is a proper way to do this.

I have studying fs module to find something.



Solution 1:[1]

you can do it

var fs = require('fs'),


 fs.readFile(__dirname + req.url, function (err,data) {
    if (err) {
      res.writeHead(404);
      res.end(JSON.stringify(err));
      return;
    }
    res.writeHead(200);
    res.end(data);
  });

For more details see here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yoel