Application error hosting Express server

Hi! This is my first time setting up a Railway project. I'm trying to host an express server on Railway, and after configuring the port setup, I get an application error when viewing from the Railway generated URL. I followed the instructions here: https://docs.railway.app/deploy/exposing-your-app Here is my server code:
const port = process.env.IS_RAILWAY ? '0.0.0.0:' + process.env.PORT : process.env.PORT || 3333;
...
app.listen(port, () => console.log(`Server runnning on port ${port}!`));
const port = process.env.IS_RAILWAY ? '0.0.0.0:' + process.env.PORT : process.env.PORT || 3333;
...
app.listen(port, () => console.log(`Server runnning on port ${port}!`));
In Railway, everything deploys correctly and my logs look good:
npm WARN config production Use `--omit=dev` instead.
> node server.js
Cloud storage access complete: arcade-app
Server runnning on port 0.0.0.0:6826!
MongoDB Connected...
npm WARN config production Use `--omit=dev` instead.
> node server.js
Cloud storage access complete: arcade-app
Server runnning on port 0.0.0.0:6826!
MongoDB Connected...
By setting up that configuration, I was able to generate a Railway URL, however when navigating to that URL, I see an application error:
Application Error

Is your app correctly listening on $PORT?

View the deployment below to check for errors
Application Error

Is your app correctly listening on $PORT?

View the deployment below to check for errors
Any ideas? Thanks!
Railway Docs
Exposing Your App | Railway Docs
Documentation for Railway
11 Replies
nebula
nebulaβ€’3y ago
const port = process.env.IS_RAILWAY ? '0.0.0.0:3333' : 3333;
...
app.listen(port, () => console.log(`Server runnning on port ${port}!`));
const port = process.env.IS_RAILWAY ? '0.0.0.0:3333' : 3333;
...
app.listen(port, () => console.log(`Server runnning on port ${port}!`));
and then set PORT on railway to 3333 easier imo
Mike Carbone
Mike CarboneOPβ€’3y ago
hmmm, okay, I can try this. I'm not sure how this is different from what I had, but let's give it a shot!
nebula
nebulaβ€’3y ago
it sets the port manually instead of relying on the automatic port
Mike Carbone
Mike CarboneOPβ€’3y ago
Gotcha, unfortunately the error persists, even when specifying the port:
> node server.js
Cloud storage access complete: arcade-app
Server runnning on port 0.0.0.0:3333!
MongoDB Connected...
> node server.js
Cloud storage access complete: arcade-app
Server runnning on port 0.0.0.0:3333!
MongoDB Connected...
nebula
nebulaβ€’3y ago
ah ok try
const port = 3333;

app.listen(port, () => console.log(`Server runnning on port ${port}!`));
const port = 3333;

app.listen(port, () => console.log(`Server runnning on port ${port}!`));
i dont think the 0.0.0.0 is needed
Mike Carbone
Mike CarboneOPβ€’3y ago
Okay interesting. I'll give that a try. That's what I had before, but couldn't trigger the "Domain" section without the 0.0.0.0 per the docs I linked. Lets see... that worked! Interesting. I wonder if I had just missed the domains section. I must've interpreted the docs wrong. Thanks for the help @neb πŸ™‚ !
nebula
nebulaβ€’3y ago
np!
Unknown User
Unknown Userβ€’2y ago
Message Not Public
Sign In & Join Server To View
Finn
Finnβ€’2y ago
please dont crosspost you have a dedicated thread for youself now oh wait this was a while ago either way
Unknown User
Unknown Userβ€’2y ago
Message Not Public
Sign In & Join Server To View
Finn
Finnβ€’2y ago
nah no worries πŸ™‚ im not the law round here anyways
Want results from more Discord servers?
Add your server