R
Railway2mo ago
Sid

What port does railway expose for node apps?

I have a very simple express app, I have it in a monorepo just to test some stuff, it builds fine, it starts fine, but I get the "application failed to respond" error when going to it on the provided domain I'm logging all traffic, and I can see that I'm not getting any when navigating to the domain I've tested the build locally, and it builds and starts just fine Any ideas?
import express from "express";
import path from "path";
import { fileURLToPath } from "url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const app = express();
const PORT = 3000;

app.use(express.static(path.join(__dirname, "dist")));

app.get("*", (req, res) => {
console.log("Request made: ", req.path);
res.sendFile(path.join(__dirname, "dist", "index.html"));
});

app
.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
})
.on("error", (err) => {
console.log(`Error: ${err}`);

process.exit(1);
});
import express from "express";
import path from "path";
import { fileURLToPath } from "url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const app = express();
const PORT = 3000;

app.use(express.static(path.join(__dirname, "dist")));

app.get("*", (req, res) => {
console.log("Request made: ", req.path);
res.sendFile(path.join(__dirname, "dist", "index.html"));
});

app
.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
})
.on("error", (err) => {
console.log(`Error: ${err}`);

process.exit(1);
});
Solution:
Each application will be assigned a random port number. Unless you specify. Your code above sets the port variable. You would want to do something like const PORT = process.env.PORT || 3000; Then when you deploy, it will use the railway provided port, which will automatically display in the selection when you add a domain...
Jump to solution
9 Replies
Percy
Percy2mo ago
Project ID: bd3d866d-5a9a-4ddc-8e35-c05a24db4b74
Sid
Sid2mo ago
bd3d866d-5a9a-4ddc-8e35-c05a24db4b74
Sid
Sid2mo ago
No description
Sid
Sid2mo ago
Here are the deploy logs which show it's running Thinking it might be a port mismatch or something
Solution
MantisInABox
MantisInABox2mo ago
Each application will be assigned a random port number. Unless you specify. Your code above sets the port variable. You would want to do something like const PORT = process.env.PORT || 3000; Then when you deploy, it will use the railway provided port, which will automatically display in the selection when you add a domain
Sid
Sid2mo ago
Ah I see
MantisInABox
MantisInABox2mo ago
If you want to continue using 3000 as your port, you must set a PORT environment variable as 3000 in your service
Sid
Sid2mo ago
Makes sense, thanks
MantisInABox
MantisInABox2mo ago
No problem
Want results from more Discord servers?
Add your server