How to Install a Node.js Discord Bot

Deploy a Node.js Discord bot like discord.js on your XGamingServer bot hosting server.

This guide covers how to deploy a Node.js Discord bot (such as one built with discord.js) on your XGamingServer.

📝 Note: You need a Discord bot token before proceeding. If you have not created one yet, follow our Create a Bot Token guide first.

Check your Startup page to see which server type you have. If you see Main File, Git Repo Address, and User Uploaded Files variables, follow the Standalone Node.js Server instructions. If you only see a Startup Command variable, follow the Discord Bot Server instructions.


Standalone Node.js Server

If your Startup page has Main File, Git Repo Address, User Uploaded Files, and Auto Update variables, you have the standalone Node.js egg. Dependencies install automatically from package.json on each start.

Option A: Upload Files

Enable User Uploads

Go to Startup and set User Uploaded Files to 1. This skips the Git clone step on startup.

Upload Your Bot Files

Go to the Files page. Upload your bot files including:

  • Your main bot file (e.g., index.js, bot.js)
  • package.json with your dependencies listed
  • Any other files your bot needs (config files, commands folder, etc.)

You do not need to upload the node_modules folder — dependencies install automatically.

Set the Main File

Go to Startup and set Main File to your bot's entry point:

index.js

Replace index.js with your actual main file name. Supports .js and .ts files.

Configure Your Bot Token

Go to Files and create a .env file with your bot token:

TOKEN=your_bot_token_here

Use whatever variable name your bot's code expects (TOKEN, BOT_TOKEN, DISCORD_TOKEN, etc.). See our Manage Bot Token guide for more details.

Start Your Server

Go to the Console page and click Start. The server will automatically run npm install and then start your bot.

Option B: Deploy from GitHub

Set the Git Repository

Go to Startup and fill in:

  • Git Repo Address — Your repository URL (e.g., https://github.com/username/my-bot)
  • Install Branch — The branch to clone (leave blank for the repo default)
  • User Uploaded Files — Set to 0 (so the server clones from Git)

Set the Main File

Set Main File to your bot's entry point (e.g., index.js).

Enable Auto Update (Optional)

Set Auto Update to 1 if you want the server to pull the latest code from GitHub on each restart.

Start Your Server

Go to Console and click Start. The server will clone the repo, install dependencies, and run your bot.

Configure Your Bot Token

After the first start, go to Files and create a .env file with your bot token. The repository is cloned to the server's file directory. Restart for the token to take effect.

Installing Additional Packages

If you need packages beyond what is in package.json, add them to the Additional Node Packages field on the Startup page (space-separated):

canvas sharp

These packages are installed automatically alongside your package.json dependencies on each start.

Using a Private GitHub Repository

On the Startup page, fill in the Git Username and Git Access Token fields. Create a personal access token with repo scope and use it as the access token.


Discord Bot Server

If your Startup page only has a Startup Command variable, you have the multi-language Discord Bot server.

Upload Your Bot Files

Log in to the XGamingServer panel and go to the Files page. Upload your bot files including:

  • Your main bot file (e.g., index.js, bot.js)
  • package.json with your dependencies listed
  • Any other files your bot needs (config files, commands folder, etc.)

You do not need to upload the node_modules folder — you will install dependencies in the next step.

Install Dependencies

Go to Startup and set the Startup Command to:

/bin/bash

Start the server. In the Console, type:

npm install

This will install all dependencies from your package.json. Wait for it to finish.

Configure Your Bot Token

Go to Files and create a .env file with your bot token:

TOKEN=your_bot_token_here

Use whatever variable name your bot's code expects (TOKEN, BOT_TOKEN, DISCORD_TOKEN, etc.). See our Manage Bot Token guide for more details.

Set the Startup Command

Go to Startup and change the Startup Command to run your bot:

node index.js

Replace index.js with your bot's main file name.

Start Your Server

Go to the Console page and click Restart. Your bot should come online and connect to Discord.

Installing Additional Packages

If you need to add more npm packages later:

Switch to Bash

Set the Startup Command to /bin/bash and restart.

Install the Package

In the Console, run:

npm install package-name

Switch Back

Set the Startup Command back to node index.js (or your main file) and restart.


Troubleshooting

  • Bot starts but immediately crashes — Check the Console for error messages. Common issues include a missing or invalid bot token.
  • "Cannot find module" errors — Dependencies are missing. On the Discord Bot server, set startup to /bin/bash, run npm install, then switch back. On the standalone Node.js server, check that your package.json lists all required dependencies.
  • Server stuck on "Starting" — The panel may not detect startup output. Join our Discord for help adjusting the configuration.
  • Wrong Node.js version — Contact support to switch the Docker image. Available versions range from Node.js 12 to 23.

How is this guide?

40% Off — Limited TimeGet your Discord Bots server todayInstant setup, DDoS protection, and 24/7 support included.
Get a Server

On this page