DEV Community

Discussion on: Node vs PHP

Collapse
 
brainbust profile image
BrainBust

There are quite a few tricks to running nodejs at scale in production and the people that have a lot of experience with it wont be very willing to share them as it's their bread and butter. But i guess the same goes for php and large scaled applications.

Here are just a few:

Cluster and cpu bind your nodejs instances, since it's single threaded you're able to cluster all your instances under a master thread (rpc bus). Use a decent process manager like pm2 that does the work for you. pm2.keymetrics.io/

Keep remembering it's event based and use it to it's full potential. Code runs topdown but logic does not. Doing something simple as 'class myEmitter extends EventEmitter' can go a very long way.

Let your app crash, if it crashes make sure it does so in an environment before production, so you can fix it. Never leave a nodejs app in an uncertain state. This goes hand in hand with making sure your app is stateless. If it crashes in production then you made a mistake that should o've never reached production deployment to begin with, costing your company money or even SLAs.

Use active frameworks, npm is one of the biggest packagers out there, both nodejs as browserland, but many package are not actively maintained, search for libraries you know will be supported and bugfixed. Like nestjs.com/