Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

164
Views
Why isn't an EventEmitter instance needed?

Below is a working example of EventEmitters.

I would have expected something like this

const EventEmitter = require('events');

class Logger extends EventEmitter {
  emitter = New EventEmitter();                 // <----

  log(msg) {
    console.log(msg);

    emitter.emit('msgLogger', {id: 1, val: 2}); // <---
  };
};

In the correct implementation, I don't understand how the EventEmitter instance is shared, as I don't see New EventEmitter() anywhere.

Just because a class requires a module, doesn't make it an instance, right?

app.js

const EventEmitter = require('events');

const Logger = require('./Logger');
const logger = new Logger();

logger.on('msgLogger', (arg) => {
  console.log('Listener called', arg);
});

logger.log('Triggered');

Logger.js

const EventEmitter = require('events');

class Logger extends EventEmitter {
  log(msg) {
    console.log(msg);

    this.emit('msgLogger', {id: 1, val: 2});
  };
};

module.exports = Logger;
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!