I'm trying to Fetch a URL (http://localhost) that will return a picture (At this moment, the extension doesn't matter) through HTTP using Node.js.
Front End
let image = await fetch('http://localhost:3031', {
mode: 'cors',
method: 'GET'
})
Back End
var http = require('http');
var fs = require('fs');
http.createServer(function (req, res) {
res.setHeader('Content-Type', 'image/png');
fs.readFile('image.png', (err, data) => {
res.write(data, "binary");
res.end();
});
}).listen(3031)
I want to take that picture and then display it into the Website.
Im getting the file, NOT THE SRC
fetching an image at all on the Client. Just use<img src='yourSource.png' />in HTML orimgElement.src = 'yourSource.png';in Front End JavaScript.http://localhost:3031, that's what you set itssrcto, i.e.<img src="http://localhost:3031" />. Usually, you only need to fetch the image in your script if you want to somehow process its binary data.