在节点进程中共享变量的最佳方法

问题描述 投票:0回答:1

假设我有两个像这样的两个过程:

file1.js

let variable1 = "variable1"

file2.js

let variable2 = "variable2"

都使用]产生的>

node file1.js
node file2.js

有没有办法让他们交流?例如,我可以从variable1获取file2.js的值吗?

假设我有两个类似的两个过程:file1.js let variable1 =“ variable1” file2.js let variable2 =“ variable2”都使用节点file1.js生成。node file2.js是否存在...] >

javascript node.js ipc node-modules shared-memory
1个回答
0
投票

如果创建主节点js和fork 2个子节点js进程,则可以在parent and child之间进行数据通信。

基本示例:

© www.soinside.com 2019 - 2024. All rights reserved.