Can't connect to server from Node JS script

I’ve got a server running on Node JS listening for messages. I now need to start another Node JS script (my client) which will send messages to the server, that’s at a specific URL and port.

I’m passing my URL into the connect function but am getting the error:

TypeError: io.connect is not a function

How can I pass my URL to connect to into this. My script is:

const io = require('');

const socket = io.connect('http://localhost:3000');
socket.on('connect', function () {
  socket.send('hello') // send to server from running JS script

143 thoughts on “Can't connect to server from Node JS script”