Error: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. while writing a simple messaging app

I am following this tutorial on youtube: https://www.youtube.com/watch?v=rxzOqP9YwmM and i’m at minute 6:30, where he shows that, with what he did, you should get ‘Hello World’ on the client console. The problem is that I don’t get it. Instead I get:

Access to XMLHttpRequest at 'http://localhost:3000/socket.io/?EIO=4&transport=polling&t=OP0hb5u' from origin 'http://localhost:5500' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I have a simple express server used to serve the static html page:

const express = require('express');
const path = require('path');
const app = express();

const root = path.join(__dirname, '..');
const PORT = 5500;

app.use('/', express.static(path.join(root, 'client')));

app.listen(5500, () => {
    console.log('Client running on port ' + PORT); 
});

a server for the backend:

const io = require('socket.io')(3000)

io.on('connection', socket =>{
    console.log('new User');
    io.emit('chat-message', 'Hello World!')
});

a simple html page with links to the scripts:

<script defer src="http://localhost:3000/socket.io/socket.io.js"></script>
<script defer src="script.js"></script>

and a client side script:

const socket = io('http://localhost:3000');
socket.on('chat-message', data =>{
    console.log(data);
});

Note the ‘Access-Control-Allow-Origin’, as I’ve found answers for similar errors that aren’t quite right
Also Note that the error comes from the first line in the client-side js (const socket = io(‘http://localhost:3000’); ), so maybe the problem isn’t on the server side, but I could be wrong.

I tried asking ChatGPT and it tells me to use a middleware in my backend to put a header to any request. Anything it told me didn’t work. Maybe the idea was right but it didn’t implement it correctly? I’m quite new to soket.io, so i don’t really know.

I tried using the HTML directly without the server but it did the exact same thing.

One thing that I noticed is that in the tutorial in the browser there isn’t any localhost or anything, instead there’s an ip adress with a port and then /index.html. Maybe that has to do with this?

Anyway, I’m really confused. Why is this, and how can I fix this?