Answer the question
In order to leave comments, you need to log in
How to emit socket events from controllers? How to organize application code?
NodeJS/Express application, standard structure, main file, separate routes, separate controllers, etc.
Now I'm trying sockets. They are connected directly to the main file. There, io.on('connection')
etc.
Of course, this is all inconvenient and this business needs to be moved. But even more confusing is this:
Let's say I want to emit a message to the entire client when I save something to the database. Those. already in the controller, where the saving to the database and the response to the client via rest api take place. How can I get it there socket.emit
?
I found only one solution when doing app.io
, but it seems to me there are other options.
How is the application structure organized if you need to be able to work with sockets across all files?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question