Just require('socket.io-client')
and run $ node client.js
as pointed out by Alfred. I confirm this works with socket.io-client
v1.4.8. To demonstrate, see the following code:
// client.js
var io = require('socket.io-client');
var socket = io('http://localhost:3000/');
socket.on('connect', function () {
socket.emit('echo', {msg: 'Hello universe!'}, function (response) {
console.log(response.msg);
socket.disconnect(); // otherwise the node process keeps on running.
});
});
The server:
// server.js
var io = require('socket.io')(3000);
io.on('connection', function (socket) {
socket.on('echo', function (data, response) {
response(data);
});
});
Spin up the server with $ node server.js
and then the client $ node client.js
in another terminal and watch the magic happening:
$ node client.js
Hello universe!
It works! A very convenient way for example to test your socket.io API.