Demo, all content is generated
Question

Render: Port scan timeout reached, no open ports detected (express)

Solved · 265 views · asked by rocco · edited

My express API deploys on Render, logs even say "Server running on http://localhost:3000", and then after a few minutes:

==> Port scan timeout reached, no open ports detected. Bind your service to at least one port. If you don't need to receive traffic on any port, create a background worker instead.
app.listen(3000, 'localhost', () => console.log('Server running on http://localhost:3000'));
What I’ve tried

Set the port to 3000 in Render environment settings, redeployed.

Comment

3 answers

Marked as helpful by the asker
chidi_eze · edited

Two things in that line:

  • 'localhost' means only processes inside the container can reach it. Render's router is outside, so it sees nothing. Bind to all interfaces.
  • Render tells you which port to use via PORT. Read it instead of hardcoding.
const port = process.env.PORT || 3000;
app.listen(port, '0.0.0.0', () => console.log(`Listening on ${port}`));

Then remove the PORT you set manually, let Render inject it.

Comment
deployed, live. chatgpt wrote 'localhost' in every example it gave me rocco · edited
Same issue with uvicorn defaulting to 127.0.0.1, for the Python folks. grace_mw · edited
Same root cause on Railway and Fly, for anyone searching. anjali_p · edited
ollie_dev · edited

Separate thing you'll notice next: Render's free tier spins the service down after inactivity, so the first request after a quiet period is slow. Not a bug in your code.

Comment
grace_mw · edited

Same fix for a Python backend on Render, since this comes up a lot:

uvicorn main:app --host 0.0.0.0 --port $PORT
Comment