Displaying images with HTML and Node.js on Raspberry Pi

I have a webserver program running with Node.js on a Raspberry Pi. I want to display images on index.html, but the images do not load/show.

I set permissions to webserver.js, index.html and my images (chmod -v 777). If I open index.html with the browser, the images show. If I type e.g. "localhost:8080/image.png" in the browser, the page does not load/show. External links from the internet work fine.


var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
var img = new Image();
img.src = 'image.png';
img.onload = () => {
    context.drawImage(img, 0, 0);

image.png is in the same folder as index.html

Also not working:

<img src='image.png'>

webserver.js: (this code is from https://www.w3schools.com/nodejs/nodejs_raspberrypi_webserver_websocket.asp)


function handler (req, res){
    fs.readFile(__dirname + '/public/index.html', function(err, data) {
        if (err) {
            res.writeHead(404, {'Content-Type': 'text/html'});
            return res.end("404 Not Found");
        res.writeHead(200, {'Content-Type': 'text/html'}); 
        return res.end();

index.html or the webserver probably cannot "reach" the images. Maybe I have to "tell" the server program to server images as well? Since I am very new to web programming, I am stuck here.

Thank you in advance.