简体   繁体   English

如何将全局变量从主线程传递给工人

[英]How to pass globals from main thread to workers

I am starting to use nodejs 12 and trying to pass from main thread that open workers I need to pass some globals this run with codeceptjs automation, The issue that before I have one main thread and now I want to handle workers also but don't know how the globals will be available on workers. 我开始使用nodejs 12并尝试从打开工作线程的主线程传递代码,我需要通过codeceptjs自动化运行来传递一些全局变量,这个问题是在我拥有一个主线程之前,现在我也想处理工作线程,但是却没有知道如何在工人身上使用全局变量。 My code for single is 我的单身代码是

  global.host =getHost();

try to use module.exports 尝试使用module.exports

example like module.exports.host = getHost(); 例如module.exports.host = getHost();

followed by: 其次是:

const n = require('./path of file you exported'); const n = require('./导出文件的路径');

n.host; n。主人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM