help icon indicating copy to clipboard operation
help copied to clipboard

Cannot use emitter.setmaxlisteners() to increase limit nodejs

Open kanakkholwal opened this issue 3 years ago • 0 comments

Details

MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [ChildProcess]. Use emitter.setMaxListeners() to increase limit

Node.js version

v16.15.0

Example code

'use strict';
const PORT = 5000;
import express from 'express';

import List from './List.json' assert {type: 'json'};
import EventEmitter from 'events';
// other modules 

class Emitter extends EventEmitter { }

const emitter = new Emitter();
emitter.setMaxListeners(100);




const app = express();
const Scrape = (RollNo, Branch, Batch) => {
// Some Function here
}
for (let i = 0; i < List.students.length; i++) {
    emitter.on('event', () => {
        console.log(i);
        Scrape(List.students[i], List.Branch, List.Batch);
    });
}

emitter.emit('event');

app.listen(PORT, () => console.log(`server running on port ${PORT}`));`

Operating system

Windows_NT

Scope

runtime

Module and version

Not applicable.

kanakkholwal avatar Oct 06 '22 10:10 kanakkholwal