Try to change your client code to:
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect();
socket.on("connect", function() {
socket.on('news', function (data) {
socket.emit('my other event', { my: 'data' });
});
});
</script>
Also, in order to be able to go to /api/1...
you need to register the corresponding app.get
, e.g. as app.get("/api/*", ...
, which would handle all the connections to /api/...
. Otherwise it is expected that you will be getting the 404 error.