DEV Community

Ebrahim Khalil
Ebrahim Khalil

Posted on

How can I decouple the socket event emitter and listener from the io connection in server?

Do you know how I can decouple the socket event emitter and listener from the io connection? Suppose for now I have to emit/listen to everything from the

`io.on("connection", async (socket) => {
console.log(User Connected: ${socket.id});

//here
socket.emit('emit something)
socket.on('listen something')
});`

but I want to emit from different places of the application, like from services. How can I achieve that?

Top comments (0)