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:
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. ...
Jump to solution
34 Replies
Rhys
RhysOP2y ago
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
Favna
Favna2y ago
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)
Rhys
RhysOP2y ago
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
Favna
Favna2y ago
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'
Rhys
RhysOP2y ago
Ah ok so I'd just whack a ENV NODE_ENV=production into the dockerfile before the run command?
Favna
Favna2y ago
Yeah, you can check out some of Dragonite, Teryl, Nekokai, Iriss, Gemboard or dockerfile. They're all open source.
Rhys
RhysOP2y ago
👍 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
Favna
Favna2y ago
Respectively under GH orgs "favware", 3x "skyra-project", and sapphire.
Sean
Sean2y ago
I'm seriously doing some calculations to work out if railway would be more cost effective for my nonprofit
Rhys
RhysOP2y ago
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
Sean
Sean2y ago
Ok, it isn't. even DO beats railway on pricing
Favna
Favna2y ago
This is a slice of the docker compose file on my server for @Dragonite
version: "3.9"

services:
redis:
command: 'redis-server --requirepass secret
container_name: redis
image: 'redis:alpine'
networks:
- infi
restart: always
logging:
options:
max-size: '20m'
max-file: '3'

dragonite:
container_name: dragonite
depends_on:
- pokedex-v7
- redis
- influx
image: ghcr.io/favware/dragonite:latest
logging:
options:
max-size: '1g'
max-file: '3'
networks:
- infi
restart: always
environment:
NODE_ENV: production
CLIENT_VERSION: 1.0.0 Kairyu
CLIENT_ID: 931264626614763530
DISCORD_TOKEN: hi

networks:
infi:
version: "3.9"

services:
redis:
command: 'redis-server --requirepass secret
container_name: redis
image: 'redis:alpine'
networks:
- infi
restart: always
logging:
options:
max-size: '20m'
max-file: '3'

dragonite:
container_name: dragonite
depends_on:
- pokedex-v7
- redis
- influx
image: ghcr.io/favware/dragonite:latest
logging:
options:
max-size: '1g'
max-file: '3'
networks:
- infi
restart: always
environment:
NODE_ENV: production
CLIENT_VERSION: 1.0.0 Kairyu
CLIENT_ID: 931264626614763530
DISCORD_TOKEN: hi

networks:
infi:
And netcup beats DO by a factor of a trillion.
Rhys
RhysOP2y ago
omg you leaked your discord client id!1!!!! ‼️
Favna
Favna2y ago
Lol
Rhys
RhysOP2y ago
(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?
Favna
Favna2y ago
DO pricing is absolutely insane compared to netcup btw kekw like I'm not joking... Yeah I don't use them much though outside of codespaces.
Sean
Sean2y ago
Yeah, Ik. I just don't want to go through the trauma of transferring a pterodactyl instance
Favna
Favna2y ago
Big sadge
Rhys
RhysOP2y ago
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
Favna
Favna2y ago
Perf isn't all there with codespaces. I'm used to better My own hardware is much faster.
Rhys
RhysOP2y ago
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
Sean
Sean2y ago
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
kyra
kyra2y ago
Favna paid for the whole PC, he's gonna use the whole PC.
Favna
Favna2y ago
True kyra
Rhys
RhysOP2y ago
i really like this part of codespaces
Rhys
RhysOP2y ago
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
kyra
kyra2y ago
Meanwhile my bots' barrier of contribution... kekw 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
Rhys
RhysOP2y ago
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 concernFrog
kyra
kyra2y ago
lol
Sean
Sean2y ago
Codespaces + public ports could be the meta for HTTP bot dev.
kyra
kyra2y ago
We go for... self-documenting functions
Rhys
RhysOP2y ago
would this help at all for it? https://docs.webhookthing.com/
Getting Started - webhookthing docs
docs for webhookthing - a thing for webhooks
kyra
kyra2y ago
I don't know, but we can move to #Coding
Krish
Krish2y ago
true true, setting up http bots is a huge pain and just don't talk about http bots in codespaces
Want results from more Discord servers?
Add your server