Scope of events from process.emit in Node.js

2019-07-29 18:58发布

问题:

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:

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

process in node.js docs