0

I've got a socket.io 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('socket.io');

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

1 Answer 1

1

If you're attempting to initiate a socket.io connection from node.js, you need the client-side library which would be:

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

And, of course, you have to install that library.

Sign up to request clarification or add additional context in comments.

1 Comment

@RyanH - Did this answer your question?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.