2 years ago
For some reason my application is saying it's failing to respond, however it successfully deploys (or at least it says so…)
I have PORT configured for Railway's default to be injected, so that isn't the issue. I also setup both my start & build scripts, which are:
Start: bun start --filter=api
Build: bun run build --filter=api
120 Replies
2 years ago
make sure you are listening on the $PORT environment variable
server.listen({ host: process.env.HOST, port: process.env.PORT }, (err, address) => {
if (err) {
Logger.error("SERVER", err.message);
process.exit(1);
}
Logger.info("SERVER", `Listening at ${address}`);
});2 years ago
there is no HOST variable, just use 0.0.0.0
HOST: z.string().default("0.0.0.0"),
API_URL: z.string().default("http://localhost:8080"),Sorry, it shouldn't been:
server.listen({ host: env.HOST, port: env.PORT }, (err, address) => {
if (err) {
Logger.error("SERVER", err.message);
process.exit(1);
}
Logger.info("SERVER", `Listening at ${address}`);
});2 years ago
what is PORT set to in zod ?
2 years ago
you should use process.env.PORT instead, and if that isn't available then you can default to 8080, not sure what that looks like in zod though
2 years ago
is it? do you have a PORT service variable?
2 years ago
you'd still want to be listening on the PORT environment variable in code though
2 years ago
would you happen to have a custom start command set now?
2 years ago
do you have the new builder also enabled? the new builder has a bug where it doesn't pass in the start command correctly
2 years ago
hmmm well those logs are not helpful, bun never prints anything helpful it seems
2 years ago
I assume you can still run the same pair of build and start commands locally without issues?
2 years ago
even if you deleted the project and did another clone?
2 years ago
on git, delete the project locally and clone it again
2 years ago
what version of bun do you use locally, and what version of bun is railway using for your project? it's always best to have the cloud platform running the same versions of stuff as you run locally
this is what my package.json looks like:
{
"name": "test",
"private": true,
"scripts": {
"build": "turbo build",
"dev": "turbo dev",
"start": "turbo start",
"lint": "turbo lint",
"format": "prettier --write \"**/*.{ts,tsx,md}\""
},
"devDependencies": {
"prettier": "^3.3.0",
"turbo": "latest"
},
"engines": {
"node": ">=18"
},
"packageManager": "bun@1.0.21",
"workspaces": [
"apps/*"
],
"dependencies": {
"tsc-alias": "^1.8.10"
}
}2 years ago
what version does railway use?
2 years ago
temporarily change the start command to a command that prints the version of bun
2 years ago
are you on the v2 runtime?
2 years ago
also, I the API app not with bun?
2 years ago
node dist/index.js
in the api package, my scripts are:
"scripts": {
"dev": "tsx watch --clear-screen=false src/index.ts",
"migrate": "drizzle-kit generate",
"build": "tsc -p tsconfig.json && tsc-alias -p tsconfig.json",
"start": "node dist/index.js"
},2 years ago
we are back to this, please make these changes
2 years ago
it's random, that's why your app needs to listen on the PORT environment variable
2 years ago
please make this change
server.listen(
{
host: process.env.HOST ?? "0.0.0.0",
port: process.env.PORT ? Number(process.env.PORT) : 8080,
},
(err, address) => {
if (err) {
Logger.error("SERVER", err.message);
process.exit(1);
}
Logger.info("SERVER", `Listening at ${address}`);
}
);2 years ago
while that will work, and it's by far the simpler way this is not the recorded way
it seems like dotenv just doesnt want to parse the env variable on railway
2 years ago
dotenv parses .env files
2 years ago
railway does not create .env files
2 years ago
they inject the variables directly into the environment
2 years ago
I don't know how I could clarify further
but when i test it by console logging, like console.log([process.env.GOOGLE](process.env.GOOGLE)_CLIENT_ID ?? "some google client id"), it doesn't work, and goes to the fallback of some google client id
2 years ago
your code is doing something to unset them
i think the issue is that the env variables are located in the root directory
2 years ago
the environment variables are injected into the containers environment, they aren't scoped to any specific directory
2 years ago
in a production environment like railway you don't even need to call dotenv
this is my src/utils/env.ts:
import "dotenv/config";
import { z } from "zod";
export const env = z
.object({
DATABASE_URL: z
.string()
.default("default db url goes here"),
// ... other variables
})
.parse(process.env);2 years ago
can zod even parse process.env
2 years ago
haha don't say yes, if it could, it would work
2 years ago
so you have something missconfigured
import "dotenv/config";
export const env = {
DATABASE_URL: process.env.DATABASE_URL || "postgres://butler:butler@127.0.0.1:5432/postgres",
// ... other variables
};2 years ago
something you are doing is un-setting them
2 years ago
try removing dotenv because as mentioned, you don't need to call it











