Maaz Zindani

Loading the index…

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

A Node.js app deployed on Railway returns Application failed to respond

ErrorApplication failed to respond

Short answer

Railway's edge proxy returns this error when it cannot reach your app. The usual cause is an app that listens on a fixed port or on localhost. Read the port from the PORT environment variable, bind to 0.0.0.0, and make sure the domain's target port matches the port the app really uses.

  • Applies to Railway, Node.js 22, Express 5
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Open the deploy logs and find the line your app prints when it starts listening. Compare the port in that line with the target port in the domain settings of the service.

    # in the code
    grep -rn "listen(" src server.js index.js 2>/dev/null
    # in the Railway dashboard, compare the service domain target port
  2. 2Match what you see, then jump to its fix

    1. 1The logs say the app started, but every request returns Application failed to respond.The app does not listen on the PORT variable or on 0.0.0.0Fix
    2. 2The app listens on a fixed port such as 8080, while the domain was set up for 3000.The domain's target port is not the port the app usesFix
    3. 3A framework CLI is the start command (next start, uvicorn) and it uses its own default port.The start command ignores PORTFix
    4. 4Requests fail only under traffic; the Metrics tab shows CPU near its limit.The app is overloaded and cannot answerFix

What does the error look like?

  • Application failed to respond
  • 502 Bad Gateway
  • Is your app correctly listening on $PORT?

Cause 1 of 4

The app does not listen on the PORT variable or on 0.0.0.0

1Check

Railway's guidance is that a web server should bind to host 0.0.0.0 and listen on the port in the PORT environment variable.

grep -rn -E "listen\(|process.env.PORT" --include=*.js --include=*.ts . --exclude-dir=node_modules

2Fix

Read PORT and bind to all interfaces.

const port = process.env.PORT || 3000;
app.listen(port, '0.0.0.0', () => {
  console.log(`listening on ${port}`);
});

3Verify

Redeploy and open the public domain.

curl -I https://your-service.up.railway.app

Confirmed by docs.railway.com

Did this fix it?

Cause 2 of 4

The domain's target port is not the port the app uses

1Check

Compare the port in the start log with the target port of the domain, shown in the service settings.

# read the deploy logs and the domain target port in the dashboard

2Fix

Change the target port to the port the app listens on, or set the PORT variable on the service so both agree.

# service variable
PORT=8080

3Verify

Wait for the redeploy and request the domain again.

curl -I https://your-service.up.railway.app

Confirmed by docs.railway.com

Did this fix it?

Cause 3 of 4

The start command ignores PORT

1Check

Railway shows framework commands that pass the port explicitly, for example next start --port with the PORT variable.

grep -n "\"start\"" package.json

2Fix

Pass the variable in the start script.

"scripts": {
  "start": "next start --port ${PORT-3000}"
}

3Verify

Redeploy and check that the deploy logs show the port from PORT.

# read the deploy logs in the dashboard

Confirmed by docs.railway.com

Did this fix it?

Cause 4 of 4

The app is overloaded and cannot answer

1Check

Open the Metrics tab of the service. For Node.js, CPU peaking near 1 vCPU points to a saturated process.

# read the deploy logs and the domain target port in the dashboard

2Fix

Add replicas to spread the load, and look for slow routes.

# raise the replica count in the service settings

3Verify

Repeat the traffic and watch the Metrics tab.

curl -I https://your-service.up.railway.app

Confirmed by docs.railway.com

Did this fix it?

How do I stop it coming back?

  • Never hard-code the port; always read PORT with a local fallback.
  • Add a simple health route and print the port at start-up so the logs show what the app actually uses.
  • Keep the target port and the PORT variable in the same place in your notes for each service.

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.