简体   繁体   English

NodeJS子节点进程

[英]NodeJS Child Node Process

I am trying to fork a child process that will go out a load data from a 3rd party api into a mongodb instance. 我正在尝试分叉一个子进程,该进程将从第三方api中将负载数据输出到mongodb实例中。 When I try to connect to mongodb inside the child process I get Error: connect EHOSTUNREACH. 当我尝试连接到子进程内的mongodb时,我得到错误:连接EHOSTUNREACH。 This is a local instance and I can connect in the parent process. 这是一个本地实例,我可以在父进程中连接。 Is this a context issue inside the child process? 这是子进程中的上下文问题吗?

In short, yes. 简而言之,是的。

You should make you code decoupling, so you can test the child_process standalone, and trace your error. 您应该使代码解耦,这样您就可以独立测试child_process,并跟踪您的错误。

To cache the error of child process, you can add below code in your entry js of your child process 要缓存子进程的错误,您可以在子进程的条目js中添加以下代码

process.on('uncaughtException', function (err) {
  console.log('Caught exception: ' + err);
});

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

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