I use NodeJS both as the server and the client. (No web browsers) Server seems to be working, but client does not connect. I tried to set the port in the options but it did not work. I try to connect to the port 3000 over telnet and it connects to something, so the server is listening. What am I missing here?


var express = require('express');
var app = express();
var path = require('path');
var server = require('http').createServer(app);
var io = require('socket.io')();
var port = 3000;

server.listen(port,"", () => {
    console.log('Server listening at port %d', port);


const io = require('socket.io-client');

const socket = io("",{reconnect:false});

socket.on('connect', function () {
    console.log('connected to the server');

1 Answers

eol On Best Solutions

As mentioned on the offical socket-io github page, you need to pass the http-server instance to the socket-io server:

var server = require('http').createServer(app);
var io = require('socket.io')(server);