Nextyhost
Pricing AMD Ryzen VPS AMD EPYC VPS Intel Xeon VPS Intel Xeon Machines AMD Ryzen 7 Machines AMD Ryzen 9 Machines AMD Game Servers Intel Game Servers Ryzen Game Servers Minecraft DDoS Shield Bot Starter Web Hosting RDP Servers Blogs Support My Account
My Account
Bot Hosting

Hosting a Node.js Discord Bot: Complete Setup Guide

NHNextyHost Team 9 min read 528 words
Deploying a Node.js Discord bot on a virtual private server

discord.js makes building bots easy; deploying one that survives reboots, restarts and updates is a different skill. This is the full path from local project to a production bot on a server.

A Discord bot is just a long-running Node process - which means everything that keeps Node apps healthy in production applies here: dependency hygiene, environment variables, a process manager, logs and monitoring. This walkthrough takes a discord.js project from your machine to a server running reliably under professional bot hosting.

Project structure that scales

Keep it boring and predictable: a commands/ folder with one file per command, an events/ folder with handlers for ready, interactionCreate and message events, a config.js that reads environment variables, and a single entry point that loads them all. Bots grow from 3 commands to 40 faster than expected, and a folder-per-command structure means adding features never touches the core.

Intents and the developer portal

Before deploying, register your application, grab the token, and configure intents. Message Content is privileged: without it your bot sees empty message content for messages from other users. Enable only what you need, because over-requesting intents delays approval and raises security questions. Also create a bot user, copy its ID, and invite it with the precise OAuth scopes (bot, applications.commands) and permissions your features require.

Server setup

  • Install Node.js LTS from your distribution or a version manager, and pin the version in package.json.
  • Create a dedicated system user for the bot; never run it as root.
  • Copy the project with git clone or SFTP and run npm ci for reproducible installs.
  • Put secrets in .env or PM2 environment config, and add .env to .gitignore.
  • Open outbound-only networking: a bot needs no inbound ports unless you expose an API.

Run it under PM2

Start with pm2 start index.js --name mybot --max-memory-restart 300M. The memory restart option handles the slow leaks that long-running Node processes accumulate. Then pm2 save and pm2 startup to persist the process list across reboots. Use pm2 logs mybot for day-to-day debugging and set up log rotation, because unrotated logs are the fastest way to fill a small disk.

Logging that helps at 3 AM

Replace console.log with a structured logger (pino or winston) that writes JSON lines with timestamps and levels. Log gateway reconnects, command errors and unhandled promise rejections - the three things that explain most "bot stopped responding" incidents. Send errors to Discord or an email channel so you are not discovering them from users.

Optional: HTTP endpoints for health checks

A tiny Express or Fastify server on localhost that returns bot status and latency lets an external monitor confirm the gateway is healthy, not just that the process exists. Point an uptime service at it through a reverse proxy if you want the monitor to reach it, or keep it internal and run the check from a cron job that posts to Discord.

Updating safely

Test locally, commit, pull on the server, run your tests, then pm2 reload mybot for a graceful restart. Keep a rollback one command away: pm2 save before risky changes so you can return to the previous state quickly. For larger bots, add a staging instance and switch commands on gradually.

Set up once and your bot behaves like a proper service: restarts itself, survives reboots, logs its failures, and tells you when something breaks.

Ready to launch on NextyHost?

Node-ready VPS with root access, SSH keys and PM2 support out of the box.

Deploy Your Bot

Frequently Asked Questions

What are privileged intents in Discord?

Presence, Server Members and Message Content intents require approval in the developer portal because they expose sensitive data. Your bot only requests the ones it truly uses, or gateway connections will be rejected.

Should I run my bot with nodemon in production?

No. Nodemon is a development tool that restarts on file changes. In production use PM2 or a systemd service, which restart on crashes and start automatically at boot.

How do I update a running bot without downtime?

Push changes, run tests, then use PM2 reload in cluster mode or a short restart window during low activity. For important bots, run two instances behind a gateway-aware setup and stop one at a time.

Related guides

Discord bot hosting online 24/7 with auto restart
Bot Hosting

How to Host a Discord Bot 24/7 (Free and Paid Options)

A bot that sleeps when your laptop closes is a prototype. Getting to true 24/7 uptime means choosing the right host, a p…

22 Sep 20268 min read
Debugging common Discord bot errors and gateway issues
Bot Hosting

12 Common Discord Bot Errors and How to Fix Them

Every Discord bot developer meets the same dozen failures. Here is what each error actually means, the fastest fix, and …

13 Sep 20269 min read
Comparison of Discord bot hosting platforms and VPS hosting
Bot Hosting

Discord Bot Hosting Compared: VPS, PaaS and Bot-Specific Hosts

Bot panels are convenient, free tiers are tempting, and a VPS gives you everything but the hand-holding. Here is how the…

07 Sep 20267 min read

More hosting guides

Setup walkthroughs, performance tips and security playbooks written by the team that runs the servers.

Browse all articles