node.jsmultithreadingcluster-computingchild-processnode-cluster

node cluster.isPrimary is undefined


Node says that cluster.isMaster is deprecated and we should use cluster.isPrimary. But, while isMaster is returning me true without problem, I getting undefined when I try cluster.isPrimary:

const cluster = require("cluster");

console.log(cluster.isPrimary); /// undefined

console.log(cluster.isMaster); /// true

Why is this happening?


Solution

  • Make sure you are on at least Node version 16.0.0

    you can see this by running this command in your terminal:

    node --version