I can't find a simple solution how to display an image on my website. I can read it in my node js backend but it will download the file instead of placing in my img tag.
Do you have a simple solution for that? Thank you very much!
HTML
let cell6 = document.createElement("td");
cell6.innerHTML = `<img src={http://localhost:4001/getImage/pexels-cottonbro-4065175.jpg}></img>`;
NODE JS
const fs = require("fs");
require("dotenv").config();
module.exports = (req, res) => {
fs.readFile(
`../backend/images/${req.params.id}`,
function (err, image) {
if (err) {
throw err;
}
console.log(image);
res.send(image);
}
);
};
srcit will either display it as an image or it will discard the resource as invalid. It won't download it. The cause must be outside the code you shared. You need to provide a minimal reproducible example.