has anyone successfully deployed a node+express server using bun+pm2 on Railway?
have a bun+express server running and trying to incorporate pm2 into the mix. I am able to get it working locally, but when I try to push the changes to Railway, it does not want to play nice.
This is what I see in the Railway Deploy Logs:
The contents of my
ecosystem.config.js
My api package.json build
and start
commands:
Solution:Jump to solution
a couple things to consider:
1 . Is your goal to use bun or node? You should pick one. Using different runtimes in development and production is adding an unnecessary layer of complexity that's also very hard to debug. dsespite what they tell you, bun is not a drop-in replacement for node (yet). I recommend sticking to node for now unless you have a practical understanding of what the differences between them are.
2. pm2 is also unnecessary complexity here, there are several other ways to accomplish the same task, the easiest of which is probably using cron and healthcheck features provided by railway for this purpose etc...
15 Replies
Project ID:
7f34b4f7-9d09-48a8-997c-32a10e59c1eb
may I ask why you'd want to use pm2 on railway?
Solution
a couple things to consider:
1 . Is your goal to use bun or node? You should pick one. Using different runtimes in development and production is adding an unnecessary layer of complexity that's also very hard to debug. dsespite what they tell you, bun is not a drop-in replacement for node (yet). I recommend sticking to node for now unless you have a practical understanding of what the differences between them are.
2. pm2 is also unnecessary complexity here, there are several other ways to accomplish the same task, the easiest of which is probably using cron and healthcheck features provided by railway for this purpose etc
at the end of the day it sounds like you have an express app that you want to run on railway. none of the things causing you problems are necessary for that, just build it with node and deploy it normally
I should've said bun+express ... we are using bun locally as well. Reasons I wanted to use pm2 was for its health & resource monitoring, and recovery mechanisms. I looked into integrating Datadog, but that seemed overly complicated with a separate hosted agent, and pm2 seemed like an easier solution. I guess APM is what I am looking for, along with continuous health checks + recovery. If there are better solutions that work well on Railway, I'm all ears!
healthchecks: https://docs.railway.app/reference/healthchecks
restarts: https://docs.railway.app/guides/healthchecks-and-restarts
cron: https://docs.railway.app/reference/cron-jobs
all of these things are first class features on railway. once you deploy a service, there's a lot you can do if you click on it and go through all the stuff available there.
thank you for these links. and as far as APM and monitoring (beyond what Railway offers), any recommendations? The 2 that I am aware of (and now 3, pm2) are Datadog and NewRelic
keep in mind railway does not offer continuous health checks
Yes, realized that. We are using the railway restart service you wrote to perform hourly restarts "just in case" .. but continuous health checks would be nice
it would definitely be nice to have
at some point health checks give way to proper redundancy. if it's that sensitive to downtime i mean.
handle exceptions in your code so your app throws less, and use the tools you mentioned for monitoring instead of disaster recovery
100% with you on that. I think we have the disaster recover part figured out at this point. just need more visibility and monitoring. Can I ask why pm2 is not a good idea on Railway? I'm mostly interested in its monitoring capabilities at this point.
not saying it's bad, ive just never considered using it on railway. webhooks fire on platform events like a service deployment crashing and i handle things from there. railways graphql API is powerful and gives me everything i need.
may still be an unpopular opinion for now but for metrics i lean into OpenTelemetry and hand roll stuff to spit in a database. in the most extreme cases ill view those metrics in a Prometheus, but rarely.
when deploying sentry i used probably 10% of that platforms capabilities for 90% of the things i needed it to do. its great, even indispensable at scale. but if you don't need it, it feels like buying a refrigerator that doesn't fit inside your doorway or something
i try to write failsafe code as possible, and then build redundancy around services that are super downtime sensitive, leaving very little monitoring or metrics gathering ever needed
this is all just sharing my experience as another customer tho
everything's a tradeoff and you know best for your project ofc :HUHH:
New reply sent from Help Station thread:
so no pm2 support on railway? is that correct? i'm inheriting a repo that uses pm2 and would like not to mess with it. not here to justify pm2 over any other solutionYou're seeing this because this thread has been automatically linked to the Help Station thread. New reply sent from Help Station thread:
Should you or should you not use pm2 on Railway aside, pm2 can work just fine on Railway if setup correctly.You're seeing this because this thread has been automatically linked to the Help Station thread. New reply sent from Help Station thread:
can you help me with how? i have pm2 installed locally and the project is running but not sure how to mirror that on railway deploymentYou're seeing this because this thread has been automatically linked to the Help Station thread. New reply sent from Help Station thread:
*installed globally locallyYou're seeing this because this thread has been automatically linked to the Help Station thread. New reply sent from Help Station thread:
I'm sorry but I have not personally set it up myself, I have only seen it integrated into other services that run on Railway just fine, such as the Directus docker image, it uses pm2 internally without issue.You're seeing this because this thread has been automatically linked to the Help Station thread.