socket.IO not connecting

it should console.log something but it’s not, does anyone know how to fix this?

server.js:

var express = require("express");
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
io.on('connection', () => {
  console.log('connected')
})
var port = process.env.PORT || 3000;
app.use(express.static(__dirname));
app.listen(port);

index.html:

<!DOCTYPE html>
<html>
  <head>
    <title>can this work</title>
  </head>
  <body>
    <h1>
      idk
    </h1>
    <script src="https://cdn.socket.io/4.0.1/socket.io.min.js"></script>
    <script>
      var socket = io().connect();
    </script>
  </body>
</html>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.