First Time Deployment.. probably port issue
alysunshyn
FREEOP

a month ago

I am trying to deploy and the deployment was smooth.. however unlike in Deno Deploy, it seems I have to choose a PORT when generating Domain.. I chose 8001 and 8080 but they both gave me this error..

Request ID:

FPobTRK0SZ6OoISJAXC71g

Please advise what am I doing wrong.. here's my server.js

```

import { config, getEnv } from "./deps.js"; // Add this import

try {
  config({ export: true });
} catch (_) {
  // No .env on Deno Deploy – this will silently fail, which is fine
}
import app from "./app.js";
import { serve } from "./deps.js";

// Prefer Deno.serve on Deno Deploy (no explicit port binding)
if (typeof Deno.serve === "function") {
  if (Deno.env.get("DENO_DEPLOYMENT_ID")) {
    // On Deno Deploy
    Deno.serve((req) => app.handle(req));
  } else {
    // On local development
    const port = Number(Deno.env.get("PORT")) || 8001;
    console.log(`Server running on port ${port}`);
    Deno.serve({ port }, (req) => app.handle(req));
  }
} else {
  // Fallback for older Deno versions
  const port = Number(Deno.env.get("PORT")) || 8001;
  console.log(`Server running on port ${port}`);
  serve((req) => app.handle(req), { port });
}


console.log("Mongo Uri:", getEnv("MONGO_URI"));

```

Attachments

Solved$10 Bounty

Pinned Solution

domehane
FREE

a month ago

i think railway is running app.js instead of server.js. that's why it never starts , you need to set the start command manually in railway go to your service , settings , deploy , start command, and set it to:

deno run --allow-all server.js

that's it, redeploy after and it should work

9 Replies

Status changed to Open Railway about 1 month ago


fra
HOBBYTop 5% Contributor

a month ago

The important thing is that your app uses the same port used in Settings=>Networking=>Public Networking, if they are the same you shouldn't have issues.

Looking at your code it seems you use the default Deno port that should be 8000 but usually railway uses the port 8080


domehane
FREE

a month ago

Hello alysunshyn;

check your deploy logs first (railway dashboard , your service , deploy logs), the real error is there not in the port selection ui

also go to your service variables tab and confirm that railway is actually injecting the PORT env var. if it is, your code already reads it correctly with Deno.env.get("PORT") so the port you pick in the domain ui doesnt matter, railway controls that

if PORT is missing from the variables tab, add it manually and redeploy

Hope this help you :)


fra

The important thing is that your app uses the same port used in Settings=>Networking=>Public Networking, if they are the same you shouldn't have issues. Looking at your code it seems you use the default Deno port that should be `8000` but usually railway uses the port `8080`

alysunshyn
FREEOP

a month ago

Thanks for the update.. but I tried 8080 and it still didn't work.. I think I'll go back to Deno Deploy.. that one's a bit more intuitive, in my opinion..


fra
HOBBYTop 5% Contributor

a month ago

can you please console Deno.env.get("PORT") in this way you can see which port your app is using


domehane

Hello **alysunshyn;** check your deploy logs first (railway dashboard , your service , deploy logs), the real error is there not in the port selection ui also go to your service variables tab and confirm that railway is actually injecting the PORT env var. if it is, your code already reads it correctly with `Deno.env.get("PORT")` so the port you pick in the domain ui doesnt matter, railway controls that if PORT is missing from the variables tab, add it manually and redeploy Hope this help you :)

alysunshyn
FREEOP

a month ago

I added PORT in the variables and tried everything else I could think of.. the logs weren't very helpful either.. I wanted an option to Deno Deploy but I think I'll stick to what works and for now, it seems it's Deno Deploy..


alysunshyn
FREEOP

a month ago

There's something that's confusing me so just sharing here.. In the build logs it shows this line..

`$ deno run --allow-all app.js`

but my application should run with 'server.js' and not 'app.js'.. am I missing something?


fra
HOBBYTop 5% Contributor

a month ago

maybe you need to update the start command? can you check if it does what you expect?

Settings=>Deploy=>custom Start command


domehane
FREE

a month ago

i think railway is running app.js instead of server.js. that's why it never starts , you need to set the start command manually in railway go to your service , settings , deploy , start command, and set it to:

deno run --allow-all server.js

that's it, redeploy after and it should work


alysunshyn
FREEOP

a month ago

Thanks @fra @domehane .. it worked!!...;-).. I got too lazy and hadn't add the start command.. but now it's all good..:-)..


Status changed to Solved brody about 1 month ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...