I'm running a node.js
app in a 32 core machine with iisnode
. IIS creates 32 processes to use all the CPU cores effectively and uses named pipes for each process.
I need to start a small task scheduler and run some other code but only in one of the processes, I don't want the 32 processes to run the same code at the same time. As this is not a node.js
cluster I can't use cluster.isMaster
and I'm not aware that iisnode
gives an ID to each process as PM2 does (read here).
Is there an easy way to run some code but only in one of all the created processes? I know I could use database lock but I was hoping to find a simpler way before having to do that.
I ended up using the proper-lockfile package that worked perfectly in my case!