DeployNodeHosting

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

  1. Listen on 0.0.0.0 and process.env.PORT.
  2. For Vite dev servers in containers: vite --host 0.0.0.0 (or server.host: true in config).
  3. On Replit, check the port mapping in the .replit file matches the port your app listens on.
  4. 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}`));
Don't: Don't hard-code a different random port. Read PORT from the environment.

Copy-paste fix prompt

3 · The fix promptPaste into Cursor, Claude Code, Codex, Lovable, Bolt, Replit or v0
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.

Related fixes

← All fixes · Still stuck? Use the diagnose-first prompt