socket.send outside of io.sockets.on( )
I think that this will successfully solve your problem
io.sockets.emit('hello')
Improving previous answer from @Nyxynyx
io.sockets.emit('hello')
It is equivalent to:
io.of('/').emit('hello');
If you need a different route, change the of
function parameter.
Documentation: https://socket.io/docs/v3/server-api/index.html#server-sockets