skip to Main Content

I have a web application. Its backend is by nodejs, and runs with pm2 and nginx.

When I do sudo pm2 logs in the server, I see the following error keeps rolling out constantly, though the main features of the application don’t seem to be disturbed.

0|npm  | index.js router.get *
0|npm  | kpi.js POST /socket.io/?EIO=3&transport=polling&t=OXijmvI
0|npm  | index.js POST /socket.io/?EIO=3&transport=polling&t=OXijmvI
0|npm  | Error: Not Found
0|npm  |     at /opt/funpro/app.js:122:13
0|npm  |     at Layer.handle [as handle_request] (/opt/funpro/node_modules/express/lib/router/layer.js:95:5)
0|npm  |     at trim_prefix (/opt/funpro/node_modules/express/lib/router/index.js:317:13)
0|npm  |     at /opt/funpro/node_modules/express/lib/router/index.js:284:7
0|npm  |     at Function.process_params (/opt/funpro/node_modules/express/lib/router/index.js:335:12)
0|npm  |     at next (/opt/funpro/node_modules/express/lib/router/index.js:275:10)
0|npm  |     at /opt/funpro/node_modules/express/lib/router/index.js:635:15
0|npm  |     at next (/opt/funpro/node_modules/express/lib/router/index.js:260:14)
0|npm  |     at /opt/funpro/routes/index.js:23:2
0|npm  |     at Layer.handle [as handle_request] (/opt/funpro/node_modules/express/lib/router/layer.js:95:5)
0|npm  |     at trim_prefix (/opt/funpro/node_modules/express/lib/router/index.js:317:13)
0|npm  |     at /opt/funpro/node_modules/express/lib/router/index.js:284:7
0|npm  |     at Function.process_params (/opt/funpro/node_modules/express/lib/router/index.js:335:12)
0|npm  |     at next (/opt/funpro/node_modules/express/lib/router/index.js:275:10)
0|npm  |     at Function.handle (/opt/funpro/node_modules/express/lib/router/index.js:174:3)
0|npm  |     at router (/opt/funpro/node_modules/express/lib/router/index.js:47:12)
0|npm  |     at Layer.handle [as handle_request] (/opt/funpro/node_modules/express/lib/router/layer.js:95:5)
0|npm  |     at trim_prefix (/opt/funpro/node_modules/express/lib/router/index.js:317:13)
0|npm  |     at /opt/funpro/node_modules/express/lib/router/index.js:284:7
0|npm  |     at Function.process_params (/opt/funpro/node_modules/express/lib/router/index.js:335:12)
0|npm  |     at next (/opt/funpro/node_modules/express/lib/router/index.js:275:10)
0|npm  |     at /opt/funpro/node_modules/express/lib/router/index.js:635:15

/opt/funpro/app.js:122:13 starts here:

// catch 404 and forward to error handler
app.use(function (req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});

If I search socket.io in the code base, I can see some, but I totally forgot why we used it and how to use it.

Does anyone know what the error is about and how to remove it?

2

Answers


  1. Socket.io is not receiving the requests, so express falls back to your error handler, resulting in the error. If socket.io is not used in the frontend you can simply remove it.

    If you require socket.io for the app, you can follow the instructions in this answer to link it up with express, which should allow it to receive its requests.

    Login or Signup to reply.
  2. From the logs, it appears that there is a request being made to /socket.io/?EIO=3&transport=polling&t=OXijmvI endpoint that your Node.js server does not know how to handle. The error you’re seeing is the 404 error being caught by the error handler in your app.js.

    Socket.IO is a library that enables real-time, bidirectional and event-based communication between the browser and the server. It uses the WebSocket protocol to provide this functionality, but if WebSockets are not available for some reason, it can fall back to other methods such as long polling, which seems to be the case here as indicated by the transport=polling parameter.

    The requests to socket.io are typically made by the Socket.IO client running in the browser when you’re using Socket.IO in your application. If you’re not using Socket.IO anymore, then you might want to remove or disable the Socket.IO client code that is making these requests.

    On the other hand, if you are using Socket.IO, you should have a handler set up to respond to these requests. Typically, when setting up Socket.IO with Express.js, you would attach it to your server instance with something like this:

    var server = require('http').Server(app);
    var io = require('socket.io')(server);
    
    server.listen(3000);
    

    Then, the Socket.IO client would be able to communicate with the server using the /socket.io/ endpoint. If you don’t have something like this in your server setup, you’ll need to add it so your server can respond to these Socket.IO requests.

    In summary, you have two options:

    1. If you’re not using Socket.IO, try to find where the Socket.IO client code is running in your frontend and remove or disable it.
    2. If you are using Socket.IO, ensure you have properly set up Socket.IO in your Node.js server to handle the requests coming from the Socket.IO client.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search