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. ...
Rhys
Rhys443d 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
Favna443d 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
Rhys443d 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
Favna443d 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
Rhys443d ago
Ah ok so I'd just whack a ENV NODE_ENV=production into the dockerfile before the run command?
Favna
Favna443d ago
Yeah, you can check out some of Dragonite, Teryl, Nekokai, Iriss, Gemboard or dockerfile. They're all open source.
Rhys
Rhys443d 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
Favna443d ago
Respectively under GH orgs "favware", 3x "skyra-project", and sapphire.
Sean
Sean443d ago
I'm seriously doing some calculations to work out if railway would be more cost effective for my nonprofit
Rhys
Rhys443d 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
Sean443d ago
Ok, it isn't. even DO beats railway on pricing
Favna
Favna443d 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
Rhys443d ago
omg you leaked your discord client id!1!!!! ‼️
Favna
Favna443d ago
Lol
Rhys
Rhys443d 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
Favna443d 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
Sean443d ago
Yeah, Ik. I just don't want to go through the trauma of transferring a pterodactyl instance
Favna
Favna443d ago
Big sadge
Rhys
Rhys443d 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
Favna443d ago
Perf isn't all there with codespaces. I'm used to better My own hardware is much faster.
Rhys
Rhys443d 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
Sean443d 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
kyra443d ago
Favna paid for the whole PC, he's gonna use the whole PC.
Favna
Favna443d ago
True kyra
Rhys
Rhys443d ago
i really like this part of codespaces
Rhys
Rhys443d 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
kyra443d 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
Rhys443d 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
kyra443d ago
lol
Sean
Sean443d ago
Codespaces + public ports could be the meta for HTTP bot dev.
kyra
kyra443d ago
We go for... self-documenting functions
Rhys
Rhys443d ago
would this help at all for it? https://docs.webhookthing.com/
Getting Started - webhookthing docs
docs for webhookthing - a thing for webhooks
kyra
kyra443d ago
I don't know, but we can move to #Coding
Krish
Krish443d 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
More Posts
speakerName translation in FFXIVIpcChatHello everyone, I'm using ffxiv-pcap to read chat messages using the Sapphire Struct for chat messagClearing registered slash commandsHello 👋 I would like to know if there's a system provided by Sapphire to automatically clear previDocker being goofyI have no idea why Docker is being all goofy, it's saying that my discord token is invalid, but it'sReferenceError: [ENV] BOT_OWNER_IDS - The key must be an array, but is empty or undefined.I am using `@skyra/env-utilities` and when I start up my bot, I get the error reported in the title How can I turn a joinedTimestamp into this Discord TimestampThe one that automatically shows you like how long ago this timestamp wasHow to use `@sapphire/shapeshift ` dateValid & stringRegexI have a slash command that needs to take in a date input in the format of `YYYY-MM-DD`. I want to Access extended sapphire clientFollowing usecase: I extended the sapphire client in order to create custom collections etc. Is thVersion mismatch between Sapphire and dapi-typesHi, I was updating my dependencies when I encountered Discord.js' dapi-types error. I copy/pasted thWhats the syntax to require Permission X AND Y OR Z when using requiredUserPermissionswhen using `requiredUserPermissions`. Its an array so Im not sureGetting modalSubmit error over the weekendDid discord change something???How to use windows env variables using skyra env utilitiesi am trying to use CD for hosting and i have env variables set on windows, how do i access them withPattern for fetching all registered slash commandsI have some slash commands and some with subcommands and and want to introduce a `/help` slash comminteraction.showModal not workinginteraction.showModal doesnt work, I dont know why. Code: ``` this.container.logger.debug("Start EdPrecondition with Slash CommandHow to report precondition failure w/ clash command? If I use `this.error({ message: 'error' });` iHow to use skyra env utilities with the cli generated project?I want to use env variables to store my mongo uri, but due to skyra utilities being their i cant useHow to get the current channel a slash command was used inI took a look at the following post https://discord.com/channels/737141877803057244/1061609301556346Preventing Commands in DMsHow do you prevent commands from being used in DMs? Message commands.autoModerationActionExecution EventDoes Sapphire not emit the Discord.js `autoModerationActionExecution` event? The following code doeHelp canceling a commandHere the code I have for a simple reminder command.https://pastebin.com/crRSdjEn. It works but id liHow to check if the bot has Permission X inside of the server? For example VIEW_AUDIT_LOGIn a listener