1

I am having a similar problem as in this question:

node.js - request - How to "emitter.setMaxListeners()"?

the user seemed to have solved their problem, but I'm not sure how they did it. ("process.setMaxListeners(0)"???) what is "process"?

Community
  • 1
  • 1
victormejia
  • 1,174
  • 3
  • 12
  • 30
  • 3
    Read the Node docs. [process](http://nodejs.org/api/process.html#process_process), [EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter) – timidboy Aug 28 '12 at 01:45

2 Answers2

3

I suppose that 'process' in the context of that question refers just to SOME EventEmitter class. In fact, if you have some object that is EventEmitter and get the same error, you should add to your code something like this (before adding listeners):

request.setMaxListeners(0); 

Here can be request, process or any other object that causes the problem. However, sometimes such an error signalizes about design error. If you show your code, it will be possible to give more precise recommendation.

Mariya Davydova
  • 1,353
  • 9
  • 14
0

process is the global process. It is an EventEmitter. The node.js api documentation says this:

The process object is a global object and can be accessed from anywhere. It is an instance of EventEmitter. (http://nodejs.org/api/process.html)

You can do things like set global event listeners, remove global event listeners, emit global events, pretty much anything you can do with an EventEmitter.

process.on("GlobalEvent", GlobalEventHandler);
process.emit("GlobalEvent");
do something. . .  .
process.removeListener("GlobalEvent", GlobalEventHandler);

I used this to emit events from one module across to another module I was running under same overall process. That allowed me to keep them in nice little functional modules but still have the ability to emit events to one another.

Brian
  • 3,264
  • 4
  • 30
  • 43