ExpressJS app not responding

Hello! I am currently trying to deploy my ExpressJS app with only one basic feature. It works on localhost. But on the deployed domain I see none of the console log's in the deploy page and also get no responses when making API requests to it, using CURL. Here's my code:
import express from "express";
import { Readable } from "stream";
const app = express();

const messages = ['Hey!', 'How are you?', 'Thanks suXin for help :birb:'];

app.get('/', (req, res) => {
console.log("New request");
var i = 0;
res.setHeader('Content-Type', 'text/plain');

const readable = new Readable();
readable._read = () => {}; // Required for a readable stream

const interval = setInterval(() => {
readable.push(`${messages[i]}\n`);
console.log(messages[i]);
i++;

if (i >= messages.length) {
clearInterval(interval);
readable.push(null);
}
}, 1000);

readable.pipe(res);
});

app.get("/health", (req, res) => {
res.status(200).send({
status: "OK"
});
})

app.listen(3000, () => {
console.log("Listening on port 3000");
});
import express from "express";
import { Readable } from "stream";
const app = express();

const messages = ['Hey!', 'How are you?', 'Thanks suXin for help :birb:'];

app.get('/', (req, res) => {
console.log("New request");
var i = 0;
res.setHeader('Content-Type', 'text/plain');

const readable = new Readable();
readable._read = () => {}; // Required for a readable stream

const interval = setInterval(() => {
readable.push(`${messages[i]}\n`);
console.log(messages[i]);
i++;

if (i >= messages.length) {
clearInterval(interval);
readable.push(null);
}
}, 1000);

readable.pipe(res);
});

app.get("/health", (req, res) => {
res.status(200).send({
status: "OK"
});
})

app.listen(3000, () => {
console.log("Listening on port 3000");
});
How would I fix it?
Solution:
use the PORT environment variable provided by railway instead of specifying a port
Jump to solution
10 Replies
Percy
Percy2y ago
Project ID: bca4093c-a405-41ff-a5d8-243b3bb9a985
lennard.
lennard.2y ago
My ID: bca4093c-a405-41ff-a5d8-243b3bb9a985
Solution
epik!
epik!2y ago
use the PORT environment variable provided by railway instead of specifying a port
epik!
epik!2y ago
make sure it's listening on 0.0.0.0
lennard.
lennard.2y ago
So process.env.PORT?
epik!
epik!2y ago
i don't know js i just took a quick look at the code
lennard.
lennard.2y ago
Okay, thanks!
epik!
epik!2y ago
let me know if it works
lennard.
lennard.2y ago
Yep, it works. Thanks a lot! @epik!
epik!
epik!2y ago
no problem
Want results from more Discord servers?
Add your server