I was following this basic tutorial, when I quickly found out that socket.io doesn't seem to detect my index.html and localhost gives error message 404. So maybe I had mistyped something, thus I copied the files from the tutorial, but the same issue persists. What am I missing?
Socket.io by itself ONLY responds to socket.io requests, not regular web page requests. So, if you want your server to both work with socket.io and be a regular web server to serve web pages, then you will need to integrate a regular web server together with your socket.io code.
The socket.io web site has an example of how to use socket.io WITH Express like here. The basic concept (from the socket.io doc) is this:
const express = require('express');
const app = express();
const http = require('http');
const server = http.createServer(app);
const { Server } = require("socket.io");
const io = new Server(server);
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
io.on('connection', (socket) => {
console.log('a user connected');
});
server.listen(3000, () => {
console.log('listening on *:3000');
});