I have an in memory javascript object which I initialize when node boots up. I am running this node app on multiple cores using cluster module. When I receive an http request,it is received by one of the worker threads, changes the value of the javascript object. I need to make sure that this changed value is reflected for all worker threads? How should I do it?
Child processes cannot share variables, because each worker is a full-featured process created with child_process.spawn.
Use a fast, in-memory, key-value database like Redis and node-redis to do this.
This way, when your app boots you can serialize your JS object and assign it to a Redis key. Then, workers will do all the read-update operations on the same key. I personally recommend this way.