I\'ve searched a lot to figure out this question, but I didn\'t get clear explanation. Is there only one difference thing that clustered app can be scaled out and forked app
Documentation and sources are really misleading here.
Reading up on this in the sources, the only differences seems to be, that they use either node cluster
or child_process
API. Since cluster
uses the latter, you are actually doing the same. There is just a lot more custom stdio
passing around happening inn fork_mode
. Also cluster
can only be communicated with via strings, not objects.
By default you are using fork_mode
. If you pass the the -i [number]
-option, you're going into cluster_mode
, which you generally aim for w/ pm2
.
Also fork_mode
instance probably can't listen on the same port due to EADDRINUSE
. cluster_mode
can. This way you also can structure you app to run on the same port being automatically load balanced. You have to build apps without state then though e.g. sessions, dbs.