Running in production
Hey! What's the recommended method for starting up a node app in production? Specifically for DiscordJS - I was looking into pm2 but would love if anyone has other resources / recommendations - thanks!
Solution:Jump to solution
pm2 works but I would recommend Docker. For one it allows you to mimick your entire environment locally first and not quickly run into unexpected differing environment issues. When you use a docker compose file you can also configure quite a lot of the service(s). I assume @Answer Overflow has some kind of database for example which you can also run in docker. If you run that baremetal right now, you'd have to data dump and data import.
Other useful features of docker are
- built in limiting of resources per service
- built in environmental file or inline loading. ...
34 Replies
MDN says to just do NODE_ENV=production https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/deployment#set_node_env_to_production but somehow I feel like there's a better option
Express Tutorial Part 7: Deploying to production - Learn web develo...
That's the end of this tutorial on setting up Express apps in production, and also the series of tutorials on working with Express. We hope you've found them useful. You can check out a fully worked-through version of the source code on GitHub here.
Solution
pm2 works but I would recommend Docker. For one it allows you to mimick your entire environment locally first and not quickly run into unexpected differing environment issues. When you use a docker compose file you can also configure quite a lot of the service(s). I assume @Answer Overflow has some kind of database for example which you can also run in docker. If you run that baremetal right now, you'd have to data dump and data import.
Other useful features of docker are
- built in limiting of resources per service
- built in environmental file or inline loading.
- built in log entry limits (for pm2 you'd want to use pm2-logrotate which is just extra overhead)
https://github.com/AnswerOverflow/AnswerOverflow/blob/main/apps/discord-bot/Dockerfile Production dockerfile is here so that's a nice start, deploying it via railway if you're familiar with that so all of those are built in
GitHub
AnswerOverflow/Dockerfile at main · AnswerOverflow/AnswerOverflow
Indexing Discord Help Channel Questions into Google - AnswerOverflow/Dockerfile at main · AnswerOverflow/AnswerOverflow
You can set such env vars in the pm2.ecosystem.yml and then load a specific env file with dotenv-cra but the same goes for docker where you can set it with
environment
key in the yaml file, or even better, in the Dockerfile used to build the image.
I'm not familiar with railway. I only ever used direct VPS'Ah ok so I'd just whack a ENV NODE_ENV=production into the dockerfile before the run command?
Yeah, you can check out some of Dragonite, Teryl, Nekokai, Iriss, Gemboard or dockerfile. They're all open source.
👍 thanks! I'll check those out
finally getting the open source version of answer overflow out the door in the next few weeks, really excited
Respectively under GH orgs "favware", 3x "skyra-project", and sapphire.
I'm seriously doing some calculations to work out if railway would be more cost effective for my nonprofit
for me its the convince, ive done a VPS deployment before and hated it
its really nice peace of mind knowing everything should be setup correctly and just works, lets me focus on what i enjoy
its also pretty decently priced from what i can tell
Ok, it isn't. even DO beats railway on pricing
This is a slice of the docker compose file on my server for @Dragonite
And netcup beats DO by a factor of a trillion.
omg you leaked your discord client id!1!!!! ‼️
Lol
(thanks for sharing, i honestly really love docker/docker-compose)
its such a nice feeling just running one command and having everything work
have you seen VSCode dev containers?
DO pricing is absolutely insane compared to netcup btw like I'm not joking...
Yeah I don't use them much though outside of codespaces.
Yeah, Ik. I just don't want to go through the trauma of transferring a pterodactyl instance
Big sadge
For AO since it needs Elastic, MySQL, Redis, and optionally Kibana to run I've got it all in a dev container docker compose file which starts up when I open VSCode <:Chef_Kiss:1013876149610348614>
thing of beauty
also codespaces are goated i love them
Perf isn't all there with codespaces. I'm used to better
My own hardware is much faster.
i dont really need them for my own development since ive got all my stuff setup but it makes it super easy for new contributors to try some things out
yeah thats fair
Codespaces wasn't built for people who already have powerful hardware. It was built for people who don't or can't use it. and for that it's fast enough
Favna paid for the whole PC, he's gonna use the whole PC.
True kyra
i really like this part of codespaces
throwing a button on your readme to increase conversions of people who just give a try of contribuitng to your OSS project
since it takes all of the barriers away to getting setup it's a great way to introduce people to the project
Meanwhile my bots' barrier of contribution... out, HTTP bots are much harder to self-host and even test
Good think you don't have that barrier as you're looking for contributors
yeah one of the original goals of this rewrite was to keep it as open to contributors as possible so that drove a lot of decisions
except for commenting my
lol
Codespaces + public ports could be the meta for HTTP bot dev.
We go for... self-documenting functions
would this help at all for it? https://docs.webhookthing.com/
Getting Started - webhookthing docs
docs for webhookthing - a thing for webhooks
I don't know, but we can move to #Coding
true true, setting up http bots is a huge pain and just don't talk about http bots in codespaces