R
Railway•8mo ago
Kweebac

Trying to deploy my backend but it always says "Application failed to respond"

Here's the repo: https://github.com/Kweebac/messagingApp/ I started a new project, created a MongoDB database and added the shared variable MONGO_PRIVATE_URL, added all my other ENV variables, changed the root directory to /server and generated a domain. The deployment worked, but when I go to the domain it says "Application failed to respond". In the logs it says this, and keeps restarting over and over.
No description
Solution:
I wouldn't recommend using nodemon in production
Jump to solution
45 Replies
Percy
Percy•8mo ago
Project ID: N/A
Fragly
Fragly•8mo ago
make sure your app is listening on the PORT provided by Railway I recommend you check this out: https://docs.railway.app/guides/fixing-common-errors
Kweebac
Kweebac•8mo ago
Thank you, I didn't know about this And wow that was a quick response lol
Fragly
Fragly•8mo ago
no problem 🙂
Kweebac
Kweebac•8mo ago
Fixed, thank you :)
Fragly
Fragly•8mo ago
Awesome, I'm happy to help! :D
Kweebac
Kweebac•8mo ago
Just noticed it's still giving me this error and restarting over and over, yet on the domain it seems fine?
No description
Kweebac
Kweebac•8mo ago
Can I just ignore this lol
Fragly
Fragly•8mo ago
Mind sending me a screenshot of your memory metrics in your service?
Kweebac
Kweebac•8mo ago
How do I do this? Not sure what memory metrics are haha
Fragly
Fragly•8mo ago
in your service you'll see a Metrics tab
No description
Fragly
Fragly•8mo ago
you can click on that to see your application's metrics, it shows info about your app's cpu, memory and network usage
Kweebac
Kweebac•8mo ago
No description
Fragly
Fragly•8mo ago
dang your app uses next to no memory, what the flip
Kweebac
Kweebac•8mo ago
Is that a good or a bad thing...
Fragly
Fragly•8mo ago
typically a good thing but I feel this may not be intended here I'm wondering if your app may be trying to allocate more than 500mb of memory quickly after starting up, and if that fails your app exits making it show no memory usage even though it wants to use a ton of memory
Kweebac
Kweebac•8mo ago
So I need to increase the 500mb cap or something?
Fragly
Fragly•8mo ago
If I'm right then yes that would be the solution, and you can do that by upgrading to hobby plan ( which increases the cap from 500mb to 8gb ) Although, I'm not 100% certain that this is in fact the issue
Kweebac
Kweebac•8mo ago
I have the frontend hosted on Vercel and it seems to be communicating with the backend correctly though lol This is strange
Fragly
Fragly•8mo ago
oh, maybe it's just an operation in your app that's failing to allocate the required memory instead of your entire app then 🤔 oh well, if it works it works 😆
Kweebac
Kweebac•8mo ago
The backend just crashed so I take that back 😅
Fragly
Fragly•8mo ago
oh 💀 then this is still my best guess about what's happening
Kweebac
Kweebac•8mo ago
Do most MERN apps need more than 500mb of memory allocated like this or have I just wrote bad code or something lol
Fragly
Fragly•8mo ago
wait one last idea, could you try setting a NODE_OPTIONS service variable to --max-old-space-size=8192
Kweebac
Kweebac•8mo ago
Haha well the error changed Now it just says "Killed" And restarts over and over After doing this
Fragly
Fragly•8mo ago
it largely depends on your app itself, like how big of a userbase it has and what specifically goes on inside of it, I use a similar stack and my apps use around 100mb to 300mb depending on the scale okay definitally a step in the wrong direction then 🤣 I'm gonna go ahead and lock in on this then Feel free to wait for a second opinion though Maybe someone else has an idea
Kweebac
Kweebac•8mo ago
I also get a CORS error now interestingly I'll try upgrading to Hobby plan
Fragly
Fragly•8mo ago
Sounds good, hopefully that does solve your issue
Kweebac
Kweebac•8mo ago
Nice I get a $5 discount anyway so it's basically free Yeah... I've been trying to host my website for 2 days now and I can confidently say it's the worst part of webdev 😭
Fragly
Fragly•8mo ago
lmao, fr Railway's mission is to make it the easiest part of web dev 🚀
Kweebac
Kweebac•8mo ago
Damn it It seemed like it was fixed then it just sent the error again haha
Fragly
Fragly•8mo ago
Darn, that's unfortunate
Kweebac
Kweebac•8mo ago
Bit of a bigger error this time, looks mostly similar though
No description
Kweebac
Kweebac•8mo ago
It restarts every minute or so now instead of immediately like last time
Fragly
Fragly•8mo ago
so it runs for about a minute before crashing?
Kweebac
Kweebac•8mo ago
Yeah lol The Railway deployment doesn't crash It just restarts it every minute
Kweebac
Kweebac•8mo ago
Solution
Fragly
Fragly•8mo ago
I wouldn't recommend using nodemon in production
Fragly
Fragly•8mo ago
nodemon is strictly meant for development
Kweebac
Kweebac•8mo ago
Nice to know, I'll try fixing that now lol Honestly the first 2 days I tried doing this I didn't even know the frontend and backend were meant to be deployed separately LOL So just node instead?
Fragly
Fragly•8mo ago
exactly
Kweebac
Kweebac•8mo ago
Seems to be working now, API calls do feel noticeably slower now that I'm not using localhost, is this normal?
Fragly
Fragly•8mo ago
yea, when you're testing locally then your apps are in the same machine and so requests are practically instant as opposed to running in development where the server is usually far away from the client computer your deployment is running in US-west, so if you're far away from western US then API calls will be significantly slower
Kweebac
Kweebac•8mo ago
Ah okay, thank you for all your help :) This whole experience was just depressing lol, time to go do fun things with my life again
Fragly
Fragly•8mo ago
lmao, enjoy! of course, any time :SmileFluent:
Want results from more Discord servers?
Add your server