Before you deploy

Deploying a Node.js Discord bot means moving it from your local machine to a server where it runs continuously. Before you begin, make sure your bot works correctly on your local machine. Test all commands, verify error handling, and confirm your bot connects to Discord without issues. Deploying a broken bot to a server just moves the problem somewhere harder to debug.

Prerequisites

  • A working Discord bot built with Node.js (discord.js, Eris, or another library)
  • Node.js 18 or later installed locally for development
  • A Discord bot application created in the Developer Portal
  • Your bot token (stored securely, never in source code)
  • An SFTP client like FileZilla or WinSCP for file uploads

Project structure

A clean project structure makes deployment straightforward. Before uploading to a host, your project should look like this:

my-discord-bot/
├── node_modules/       # Dependencies (install on server or upload)
├── commands/           # Command files (if using command handler)
│   ├── ping.js
│   └── help.js
├── events/             # Event handlers (optional)
│   ├── ready.js
│   └── messageCreate.js
├── .env                # Environment variables (token, config)
├── .gitignore          # Excludes .env and node_modules
├── index.js            # Main entry point
├── package.json        # Dependencies and scripts
└── package-lock.json   # Locked dependency versions

The critical files

package.json tells the hosting platform what dependencies your bot needs and how to start it. Make sure it includes a start script and lists all dependencies:

{
  "name": "my-discord-bot",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "dependencies": {
    "discord.js": "^14.14.1",
    "dotenv": "^16.4.1"
  }
}

package-lock.json locks your dependency versions so the same versions install on your hosting server as on your local machine. Never delete this file. It prevents subtle bugs caused by dependency version drift.

Environment variables

Your bot token and any configuration values that change between environments belong in environment variables, not in your code. This is both a security requirement and a deployment best practice.

Setting up dotenv

npm install dotenv

Create a .env file in your project root:

DISCORD_TOKEN=your_bot_token_here
PREFIX=!
OWNER_ID=123456789012345678

Load it at the top of your main file:

require('dotenv').config();

const { Client, GatewayIntentBits } = require('discord.js');

const client = new Client({
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.MessageContent
    ]
});

client.once('ready', () => {
    console.log(`Logged in as ${client.user.tag}`);
});

client.login(process.env.DISCORD_TOKEN);

For a comprehensive guide on environment variable management, read our environment variables guide.

Preparing for deployment

Install production dependencies only

If you have development dependencies like nodemon or eslint, they do not need to be on your hosting server. Your package.json should separate dependencies from devDependencies:

{
  "dependencies": {
    "discord.js": "^14.14.1",
    "dotenv": "^16.4.1"
  },
  "devDependencies": {
    "nodemon": "^3.0.2",
    "eslint": "^8.56.0"
  }
}

Test your start command locally

Before deploying, run your bot using the exact start command you will use on the server:

node index.js

If this works locally, it will work on the hosting platform. If you have been using nodemon index.js during development, make sure node index.js also works. MonkeyBytes supports both Node.js and Nodemon runtimes, so you can choose either. See supported bot types for details.

Check your .gitignore

Before uploading anywhere, verify your .gitignore excludes sensitive files:

# Environment variables
.env
*.env
.env.*

# Dependencies (if installing on server)
node_modules/

# OS files
.DS_Store
Thumbs.db

# IDE files
.vscode/
.idea/

Deploying to MonkeyBytes

MonkeyBytes provides a pre-configured Node.js environment with 1 GB RAM, 1 GB SSD storage, and 150% CPU. You do not need to install Node.js or configure a process manager. The platform handles all of that.

Step 1: Create your bot instance

Log in to the MonkeyBytes dashboard and create a new server. Select the Node.js runtime. Your server is provisioned instantly with SFTP credentials displayed on the dashboard.

Step 2: Enable maintenance mode

Before uploading files, enable maintenance mode from the dashboard. This prevents the server from trying to run incomplete code while you are still uploading files. This is a safety feature that prevents partial deployments.

Step 3: Upload via SFTP

Connect to your server using the SFTP credentials from the dashboard. Use FileZilla, WinSCP, or any SFTP client.

Upload these files to the server root:

  • index.js (or your main entry file)
  • package.json
  • package-lock.json
  • .env (with your bot token)
  • Any additional source files (commands/, events/, etc.)
  • node_modules/ (upload your local node_modules, or install on server)

Step 4: Install dependencies (if not uploaded)

If you did not upload node_modules/, use the web console in the dashboard to install dependencies:

npm install --production

This reads your package.json and installs only production dependencies.

Step 5: Configure the start command

Set your start command in the dashboard. For most bots, this is:

node index.js

If your main file has a different name, adjust accordingly. If you are using Nodemon runtime, the command would be:

nodemon index.js

Step 6: Disable maintenance mode and start

Disable maintenance mode, then start your bot from the dashboard. The real-time console shows your bot's output. You should see your ready event fire and your bot come online in Discord.

Common deployment issues

Missing dependencies

If your bot crashes with Cannot find module 'xyz', the dependency is not installed on the server. Check your package.json includes the missing package, then run npm install from the console.

Wrong Node.js version

Discord.js v14 requires Node.js 16.11 or later. If you use modern JavaScript features like optional chaining (?.) or nullish coalescing (??), you need Node.js 14+. MonkeyBytes provides a current Node.js version that supports all modern syntax.

Token not loading

If your bot fails to log in, verify your .env file is uploaded and in the correct location (project root). Check that dotenv is installed and require('dotenv').config() is called before client.login(). Use the console to verify:

console.log('Token exists:', !!process.env.DISCORD_TOKEN);

Port binding errors

Discord bots do not need to bind to a port. If you see errors about port binding, remove any Express or HTTP server code that tries to listen on a port. Bot hosting platforms do not expose web ports for bot instances.

Memory issues

If your bot crashes with JavaScript heap out of memory, you may have a memory leak or your bot is caching too much data. Common causes include storing entire message histories in memory, not clearing intervals or timeouts, and leaking event listeners. For debugging help, see our troubleshooting guide and performance guide.

Deploying to a VPS

If your bot needs more resources or custom software, a VPS gives you full control. Here is the deployment process for a typical Ubuntu VPS.

Server setup

# Update system packages
sudo apt update && sudo apt upgrade -y

# Install Node.js via NodeSource
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs

# Verify installation
node --version
npm --version

Upload your bot

# From your local machine
scp -r ./my-discord-bot user@your-server-ip:/home/user/

Install dependencies and test

cd /home/user/my-discord-bot
npm install --production
node index.js

Set up PM2 for process management

# Install PM2 globally
sudo npm install -g pm2

# Start your bot with PM2
pm2 start index.js --name "my-discord-bot"

# Enable auto-start on server reboot
pm2 startup
pm2 save

# Useful PM2 commands
pm2 status              # Check bot status
pm2 logs my-discord-bot # View logs
pm2 restart my-discord-bot # Restart bot
pm2 monit               # Real-time monitoring

For a detailed comparison of VPS versus free hosting, read our VPS vs free hosting guide.

Post-deployment checklist

  • Bot is online and responding to commands
  • All slash commands are registered and working
  • Environment variables are loaded correctly
  • Error handling catches and logs failures gracefully
  • Bot token is not visible in any logs
  • Auto-restart is configured (automatic on MonkeyBytes, PM2 on VPS)
  • Dependencies match your local development environment

Keeping your bot updated

Deploying once is just the beginning. You will need to update your bot as you add features, fix bugs, and update dependencies.

On MonkeyBytes

  1. Enable maintenance mode
  2. Upload changed files via SFTP
  3. Run npm install if dependencies changed
  4. Disable maintenance mode and restart

On a VPS

  1. SSH into your server
  2. Pull latest code or upload new files
  3. Run npm install if dependencies changed
  4. Run pm2 restart my-discord-bot

Ready to deploy? Create a free hosting instance on MonkeyBytes and have your bot online in minutes. For the Python equivalent of this guide, read our Python deployment guide. For security best practices during deployment, see our security guide.

Guide Python Bot Deployment Guide Complete Hosting Guide Guide Security Best Practices Reference Supported Bot Types Guide Bot Troubleshooting