Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Socket.IO answers 404 on the polling request

ErrorGET /socket.io/?EIO=4&transport=polling 404 (Not Found)

Short answer

A 404 on /socket.io/?EIO=4&transport=polling means the request is not reaching a Socket.IO server. The usual causes: Socket.IO is attached to one HTTP server while app.listen starts another, client and server use different paths, or a proxy forwards only part of the URLs.

  • Applies to Socket.IO 4, Express 5, Node.js 22, nginx 1.26
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask the server directly for the handshake. A working Socket.IO server answers with a body that starts with 0 followed by a JSON object containing sid.

    curl "http://localhost:3000/socket.io/?EIO=4&transport=polling"
  2. 2Match what you see, then jump to its fix

    1. 1The curl returns Express's own Cannot GET pageSocket.IO is attached to one server and app.listen starts anotherFix
    2. 2The server works with curl on its own path, but the browser requests /socket.io/ and gets 404Client and server use different pathsFix
    3. 3404 only on the public URL; the direct curl to the app port worksThe reverse proxy does not forward /socket.io/Fix

What does the error look like?

  • GET /socket.io/?EIO=4&transport=polling 404 (Not Found)
  • Cannot GET /socket.io/

Cause 1 of 3

Socket.IO is attached to one server and app.listen starts another

1Check

app.listen creates a new HTTP server. If Socket.IO was given a different server object, nothing answers its path.

grep -n "listen(\|new Server\|createServer" server.js index.js 2>/dev/null

2Fix

Create the HTTP server yourself, pass it to both Express and Socket.IO, and call listen on it.

const express = require("express");
const { createServer } = require("http");
const { Server } = require("socket.io");

const app = express();
const httpServer = createServer(app);
const io = new Server(httpServer);

httpServer.listen(3000);

3Verify

The handshake curl now returns a body starting with 0.

curl "http://localhost:3000/socket.io/?EIO=4&transport=polling"

Confirmed by socket.io

Did this fix it?

Cause 2 of 3

Client and server use different paths

1Check

The default path is /socket.io/. Passing a path to io() as a string sets a namespace, not the request path.

grep -rn "path:" src/ public/ server.js 2>/dev/null

2Fix

Set the same path option on both sides.

// server
const io = new Server(httpServer, { path: "/my-custom-path/" });

// client
const socket = io({ path: "/my-custom-path/" });

3Verify

Request the custom path with curl.

curl "http://localhost:3000/my-custom-path/?EIO=4&transport=polling"

Confirmed by socket.io

Did this fix it?

Cause 3 of 3

The reverse proxy does not forward /socket.io/

1Check

A proxy that serves static files may route only some paths to Node.js.

grep -rn "location" /etc/nginx/sites-enabled/

2Fix

Add a location for the Socket.IO path with the Upgrade headers.

location /socket.io/ {
    proxy_set_header Host $host;
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}

3Verify

Reload nginx and request the handshake on the public host name.

sudo nginx -t && sudo systemctl reload nginx && curl "https://example.com/socket.io/?EIO=4&transport=polling"

Confirmed by socket.io

Did this fix it?

How do I stop it coming back?

  • Keep one httpServer variable and use it for every listen call.
  • Never change path on only one side; put it in shared config.
  • Keep the handshake curl as a post-deploy smoke test.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.