Scope of events from process.emit in Node.js

2019-07-29 18:54发布

I have code to sent event like this:

process.emit('event', event);

I would like to listen to these event like this:

process.on('event', function(event) {
     //HANDLING LOGIC
});

It works fine when files are located in the same folder. When I located listener in other folder it is not fired. What can be a root cause of this and hwo can I handle it?

EDIT:

The actual problem was just a missing expose with a file including event handling. Shame on me.

1条回答
一纸荒年 Trace。
2楼-- · 2019-07-29 19:07

The process is a single global instance. the scope should not be related to your problem.

process in node.js docs

查看更多
登录 后发表回答