PM2 is a process manager for node.js application. It helps to manage and keep an application online for 24/7. In PM2 there is an option to run the code in cluster mode. The cluster mode allows node.js applications to be scaled across all CPUs available, without any code modifications. So this is a great feature in pm2.

In another side cron is a scheduler program which we can use to schedule some of our task/code to run on time basis.

In our project these two (PM2 and cron) are implemented.

Now I want to share a story about some issues…

How many times you wrote if condition in your node.js code? What about checking an objects property in if condition? How many times you needed to check an optional property of an object in an if condition? And what about that the object is a complex one, like an array or nested or mix up?

Let’s simplify the questions with an example problem.

Let’s say we have a user object and we need to print the ‘name(a property) of that object.

Let’s write a simple function to do this

function printName(user){  console.log(;}

This looks fine, but it will…

Anjarul Robin

Associate software engineer @BrainStation-23 since 2020

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store