Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

174
Visualizações
What is causing the Node.js "MaxListenersExceededWarning" warning?

I have this simple Express.js back-end server:

const app = require("express")();
const dotenv = require("dotenv");
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");

const swaggerUi = require("swagger-ui-express");
const swaggerJsDocs = require("swagger-jsdoc");

const swaggerOptions = {
  definition: {
    openapi: '3.0.0',
    info: {
      title: 'API',
      version: '0.0.1',
      description: 'Api docs .'
    },
  },
  apis: ["./src/swagger/swagger.yaml"]
};
const swaggerDocs = swaggerJsDocs(swaggerOptions);

dotenv.config();

const server = require("http").createServer(app);

app.use(cookieParser());
app.use(bodyParser.json({limit: '10MB'}));
app.use(bodyParser.urlencoded({extended: true}));
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocs));
app.use("/", require('./src/routes'));

const port = process.env.PORT || 3001;
server.listen(port, () => console.log("API listening on port " + port + "!"));

But I keep getting this warning and I actually have no idea about what is the reason for it. I don't have web sockets or something, but still:

(node:7847) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 
11 uncaughtException listeners added to [process]. 
Use emitter.setMaxListeners() to increase limit
about 4 years ago · Santiago Gelvez
2 Respostas
Responde à pergunta

0

That specific error means that your code (or the modules you are using) have added 11 handlers for the process.on('uncaughtException', ...) event.

This is typically an indication that some code is repeatedly adding the same event handler over and over again (in some other event handler such as inside an Express route) where they accumulate more and more forever. This could be in either your own code or in some module that your code imports.

Event handlers like this should be added only once for a given section of code or should be added, then removed when no longer needed.

Based on the small amount of code you show here, I'd guess that the first place to look would be in ./src/routes for any code that adds an uncaughtException listener in one of your route handlers.

about 4 years ago · Santiago Gelvez Relatório

0

I have found the reason of this warning.

In this project I use winston and winston-daily-rotate-file, for every controller and service (to write down logs) I create this logger instance, and basically this creates those handlers:

const loggerInstance = createLogger({
  level: process.env.NODE_ENV !== 'production' ? 'debug' : 'info',
  format: combine(
    colorize(),
    json(),
    label({ label: data.label ? data.label : 'NONE' }),
    timestamp(),
    myFormat,
  ),
  transports: transportsConfig,
});

if (process.env.NODE_ENV !== 'production') {
  loggerInstance.add(new transports.Console({
    handleExceptions: true,
  }));
}

if (process.env.DISABLE_LOGGER === 'yes') {
  loggerInstance.silent = true;
}

return loggerInstance;
about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda