S
S
serious9112017-03-21 12:15:36
Nginx
serious911, 2017-03-21 12:15:36

Socket.io + Express.js?

Hello.
You need to attach a Socket.io/SockJS chat to an existing Express.js application. The current application already has a defined structure/routes/models/works with a database/uploads files, etc. It is also possible to fasten work with web sockets to it.
The problem is that since Node.js runs on a single thread, working with websockets will likely slow down the rest of the application. It will also need to be able to scale to multiple servers in the future.
What is the correct way to do this in terms of architecture?
Perhaps it's better to make the chat as a separate application on the same server, that is, 2 applications will be launched:
1) chat on node.js + socket.io
2) current application on node.js + express.js
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Anton, 2017-03-21
@Fragster

it is possible to make two workers https://nodejs.org/api/cluster.html within one application (in order not to lose the database model, etc.) - one for express, the other for socket, if everything starts to slow down there, and there are a lot of cores. Although in fact it is unlikely to slow down if you use only asynchronous methods.
Well, or two applications and one + module placed in a separate repository with common things - a model, etc. then it is possible to carry these two applications on different servers.

O
OnYourLips, 2017-03-21
@OnYourLips

This is usually done by separate workers.
Commands, queue handlers (and you will definitely need queues in an asynchronous application), etc. also separate workers.
You don't need to split by application.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question