Help deploying a full stack project

I’ve deployed this app where the data is stored in a Mongo database on 2 platforms (Cyclic and Railway) where they were technically deployed but the domains were not working. I suspect this might be due to my folder structure as the front end is kept in the client folder. The app works perfectly fine locally. On Railway I see “Server running on port 3001” in the deploy logs, which is what I get locally as well. Here’s the GitHub link to the project GitHub - Montinyek/Joke-Depo: Hand-picked jokes in 7 languages stored in MongoDB
What could possibly cause an issue in deployment if it runs fine on localhost?

You are fetching from localhost in the client code on GitHub. That obviously can’t work if the backend is deployed to a host.

Or is that not the same client code you are using for the deployed backend?

I’m deploying that exact depository. So it’s a port issue?

No, it is a host issue.

localhost is a loopback address (e.g. or that only works on the local machine. Hens the name localhost.

You have to use the URI you are given when deploying the backend to whatever host you are using.

By URI you mean the domain link? Like this ? And by the way when I visit the link it says server error, would an invalid fetch request make the whole thing not even display? Because that’s a POST request too, so it gets called only on clicking a certain button

I don’t remember using Railway but you have to look at the docs for the specifics.

What to listen on

How they do environment variables

Might need an actual start script (you only have dev)

I’ve read the docs, I just didn’t find an answer there. I don’t understand what they mean by The easiest way to get up and running is to have your application listen on$PORT, where PORT is a Railway-provided environment variable.. What’s$PORT?

I think they just want the port number to be an environment variable.

How are you actually deploying the code?

I don’t think the repo you posted is set up to be a single deployment. I’m pretty sure the express server would need to be serving the client code in that case. They support monorepo but I don’t really know the specifics.

Here is their expressjs-mongoose template. It should work for the backend at least.

I assume the DB is on MongoDB Atlas?

Anyway, I’m pretty sure I would have to test and use Railway in order to give you better help because as I said, I haven’t used it.

Can you recommend a platform that you’re familiar with?

I just upload the repo from GitHub as is and add the environment variable

  • Put the server in the root.

  • Add the client code in a public folder and have express serve the client (express.static).

  • Make the client fetch against the root + route path /someRoute

  • Add the environment variables to the variables on Railway

Here is a very quick example. I wasn’t able to use your code without your DB so I just changed it to something simple. Clone or fork it if you want a copy (I might delete it at some point).

If you know React or are willing to learn it I would make this a Next.js app and deploy it to Vercel.

1 Like

Thank you, I ended up hosting the front and back ends separately and it worked

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.