App runs but the preview is blank / unreachable (bind to 0.0.0.0 and PORT)
Server started on localhost:3000 but the preview/deployed URL shows nothing or 502
In short: In containers and cloud hosts, your server must listen on 0.0.0.0 and on the port the platform gives you.
Why it happens
app.listen(3000, 'localhost') only accepts connections from inside the container, so the platform's proxy can't reach it. Many hosts (Replit, Render, Railway, Fly.io, Heroku-style platforms) also assign the port through the PORT environment variable.
How to fix it
- Listen on
0.0.0.0andprocess.env.PORT. - For Vite dev servers in containers:
vite --host 0.0.0.0(orserver.host: truein config). - On Replit, check the port mapping in the
.replitfile matches the port your app listens on. - Check the logs for the actual address and port it printed on startup.
Example
const port = Number(process.env.PORT) || 3000;
app.listen(port, "0.0.0.0", () => console.log(`listening on ${port}`));
Copy-paste fix prompt
I'm getting this error in my app: Server started on localhost:3000 but the preview/deployed URL shows nothing or 502 [Paste the full error, stack trace, and the file it points to here] Likely cause: In containers and cloud hosts, your server must listen on 0.0.0.0 and on the port the platform gives you. Task: Find where the server starts listening and make it bind to 0.0.0.0 on process.env.PORT with a sensible local fallback. Check any platform config (.replit, Procfile, Dockerfile) agrees. Rules: - First explain the root cause in 2 sentences and list the files you'll change. - Make the smallest change that fixes it. Don't refactor unrelated code. - Don't disable security or checks (RLS, auth, signature verification, type checking, CORS allow-all) to make the error disappear. - Never print or hard-code secret keys. - Finish by telling me exactly how to verify the fix.
Common with: Replit, Bolt, Cursor. Last reviewed 2026-11-13.