A Node.js app deployed on Railway returns Application failed to respond
Application failed to respondShort 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.
Fix it fast
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 port2Match what you see, then jump to its fix
- 1
The 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
The 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
A framework CLI is the start command (next start, uvicorn) and it uses its own default port.The start command ignores PORTFix - 4
Requests fail only under traffic; the Metrics tab shows CPU near its limit.The app is overloaded and cannot answerFix
- 1
What does the error look like?
Application failed to respond502 Bad GatewayIs 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_modules2Fix
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.appConfirmed by docs.railway.com
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 dashboard2Fix
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=80803Verify
Wait for the redeploy and request the domain again.
curl -I https://your-service.up.railway.appConfirmed by docs.railway.com
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.json2Fix
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 dashboardConfirmed by docs.railway.com
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 dashboard2Fix
Add replicas to spread the load, and look for slow routes.
# raise the replica count in the service settings3Verify
Repeat the traffic and watch the Metrics tab.
curl -I https://your-service.up.railway.appConfirmed by docs.railway.com
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
Back 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 fixBack end
Axios call from a React app comes back 404
404 (Not Found)
Status code 404 means a server answered, but it has nothing at that path.
3 causes, each with a fixBack end
bcrypt.hash throws 'data and salt arguments required'
Error: data and hash arguments required
The bcrypt package throws this when hash gets null or undefined for the password or for the salt.
4 causes, each with a fixBack end
bcryptjs rejects hash() or compare() with Illegal arguments
Error: Illegal arguments: string, undefined
bcryptjs checks the types of its two arguments and, when either is wrong, throws Illegal arguments followed by the typeof of the first and the second.
3 causes, each with a fixBack end
Express warns 'body-parser deprecated undefined extended'
body-parser deprecated undefined extended
The warning appears because urlencoded() was called without the extended option, which body-parser 1.x has warned about since version 1.4.0.
3 causes, each with a fixBack end
Browser blocks a stylesheet or script: MIME type mismatch with nosniff
The Network tab shows the asset URL answered with Content-Type text/html
With X-Content-Type-Options: nosniff the browser accepts a stylesheet only as text/css and a script only as a JavaScript type.
3 causes, each with a fix