Websocket in nodejs does not work after page refresh

Hey I am getting into Node.js with express and I tried to use Websockets for Client-Server communication. The communication works fine until the client refreshs the page for some reason. The then newly created Websocket connection does not get all messages from the server.
HTML part (I know that the messages are sent twice to the client, I was just trying both of them)

// Create WebSocket connection.
const socket = new WebSocket("ws://localhost:8080");

// Listen for messages
socket.addEventListener("message", (event) => {
  console.log("Message from server ", event.data);
  document.getElementById("data_field_id").textContent = event.data;
});

socket.onmessage = function (event) {
  console.log("Message from server ", event.data);
   document.getElementById("data_field_id").textContent = event.data;
};

// Log WebSocket close event
socket.addEventListener("close", (event) => {
  console.log("WebSocket is closed now.");
});

// Log WebSocket error event
socket.addEventListener("error", (event) => {
  console.error("WebSocket error observed:", event);
});

The javascript nodejs code looks like this:

app.listen(3000, () => {
    console.log("It Works!");
});

app.get('/', (req, res) => {
    res.sendFile('index.html', {
        root: './'
    });
})

wss.on('connection', (ws) => {
    

    console.log("Client connected");
    ws.send(" Server ready...");

    setTimeout(function () {
        ws.send("AWAITED") // will be executed after the specified time
    }, 5000);

    function sendUpdate(status) {
        ws.send(status);
    }
    
    ws.on('close', () => {
        console.log('Client disconnected');
    });



    app.get('/download', async (req, res) => {
        firstStepInDownload();
        sendUpate("FIRST STEP DONE");
    }
    firstStepInDownload{
       // This method sends status updates while processing
       ws.send("RUNNING FIRST STEP")
       }

The thing is now that when going onto localhost it works fine. Client gets all messages “Server ready…”, “AWAITED”, “RUNNING FIRST STEP” and “FIRST STEP DONE”. But when I refresh the page, only the “Server ready…” message and the “AWAITED” message are sent for some reason. The other two are not sent to the client when triggering the processing. Can someone tell why? I already tried putting the functions outside the wss. block and just forwarding the ws entity to the functions but that did not work neither. Can someone help? If you want to try it yourself I can share the github link.