Socket.IO answers 404 on the polling request
GET /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.
Fix it fast
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"2Match what you see, then jump to its fix
- 1
The curl returns Express's own Cannot GET pageSocket.IO is attached to one server and app.listen starts anotherFix - 2
The server works with curl on its own path, but the browser requests /socket.io/ and gets 404Client and server use different pathsFix - 3
404 only on the public URL; the direct curl to the app port worksThe reverse proxy does not forward /socket.io/Fix
- 1
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/null2Fix
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
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/null2Fix
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
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
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
- SessionBirdAn omnichannel engagement suite in Flutter: campaigns, chatbot, tickets, analytics and live calling.
Related fixes
Back end
The browser says io is not defined, or socket.io.js is not found
GET http://localhost:3000/socket.io/socket.io.js 404 (Not Found)
io is not defined means the Socket.IO client script never loaded.
3 causes, each with a fixBack end
Express rejects a request body as too large
413 (Request Entity Too Large) returned by nginx in front of the app
A 413 means a body was bigger than a size limit.
3 causes, each with a fixBack end
Multer upload fails with 'Unexpected end of form'
Error: Unexpected end of form
Multer reads multipart bodies with busboy, which raises this error when the request body ends before the closing boundary line.
2 causes, each with a fixBack end
Socket.IO connection blocked by CORS between your page and your Node.js server
Access to XMLHttpRequest at 'http://localhost:3000/socket.io/?EIO=4&transport=polling' from origin 'http://localhost:5173' has been blocked by CORS policy
Since Socket.IO v3 the server sends no CORS headers until you set the cors option on the Server itself.
3 causes, each with a fixBack end
WebSocket handshake fails with HTTP 400 against a Socket.IO server
{"code":1,"message":"Session ID unknown"}
A 400 during the handshake means the server understood the request and rejected it.
3 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fix