how to keep variables that share all node processes in node cluster?

前端 未结 6 1954
离开以前
离开以前 2021-02-02 12:17

It seems like all the node woker processes are working as if it is executing a new copy of the same application. But would like to keep some variables that are shared by all nod

6条回答
  •  滥情空心
    2021-02-02 12:38

    All worker processes are indeed new copies of your application. Each worker is a full featured process created with child_process.spawn. So no, they don't share variables. And it's probably best this way. If you want to share information between worker processes (typically sessions) you should look into storing these information in a database.

    If you're ready to go node all the way, you could use something like dnode to have your workers ask the master process for data.

提交回复
热议问题