ChrisD
ChrisD

Reputation: 102

Separate service on NodeJS server

I want to know how to structure my NodeJS server. I want to separate services proposed on my website to mount cluster in the future and to have many servers (each allowed to one special task).

Example :

  1. The 'main' server which have one project : ExpressJS and Database
  2. The 'communication server' which have one project : Chat + Forum
  3. Others projects : For complex computing (generating chart / stats / emailing)

Could you explain me different approach for this type of complex website ?

Upvotes: 0

Views: 721

Answers (1)

ExxKA
ExxKA

Reputation: 1030

Like Benjamin Gruenbaym said, the architecture belongs somewhere else.

If you are wondering about how to setup the applications on an individual server, there are a few things to keep in mind.

  1. NodeJS runs in a single process, so it should ideally take up 1 core of the CPU. If you run a database on the same server, that is another core. So it may be fine to host all node applications on the same server, if it has a sufficient number of cores.
  2. To run two different Node processes on the same machine, you simply start them one after another, but make sure that they listen on different ports.
  3. To make sure that you can scale out your application later, it is important that you use domain names, instead of IP adresses when you identify your services to each other. So the nodeJS app should know about the database as mydatabase.mycompany.com, not as 192.168.1.10 or any other ip address. This will allow you to later move the database to another network address or to use a load balancer.

Upvotes: 1

Related Questions