I am trying to connect client-server using socket.io however at the moment of testing my code I am getting this error http://localhost:3001/socket.io/?EIO=3&transport=polling&t=MgUqscg 404 (Not Found)
I already tried two different ways to achieve this. One returns the error already specified the second one returns an error listen EADDRINUSE :::3001
can somebody please explain to me what am I doing wrong? all tutorials seem so easy but I am stuck at this point and I really want to learn how to use sockets to improve my skills.
This is my code for server
const express = require('express');
const http = require('http');
const app = express();
// Web socket config option #1
var server = http.Server(app);
var io = require('socket.io')(server);
// Web socket config option #2
var io = require('socket.io').listen(server);
server.listen(PORT)
const PORT = process.env.PORT || 3001;
app.set('port', 3000)
io.on('connection', (socket) =>{
console.log('a user is connected')
})
app.listen(PORT, function(){
console.log(' ======= SERVER RUNNING =======');
})
This is my code for client
import * as io from 'socket.io-client';
private socket = io(`http://localhost:3001`)
I just want to connect client-server successfully without errors and print to console a success message. Thanks in advance.