# How to Install a Node.js Discord Bot (/docs/discord-bots/install-nodejs-bot)



import { Step, Steps } from 'fumadocs-ui/components/steps';

This guide covers how to deploy a Node.js Discord bot (such as one built with [discord.js](https://discord.js.org/)) 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](/docs/discord-bots/create-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](#standalone-nodejs-server) instructions. If you only see a **Startup Command** variable, follow the [Discord Bot Server](#discord-bot-server) instructions.

***

Standalone Node.js Server [#standalone-nodejs-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 [#option-a-upload-files]

<div className="fd-steps">
  <div className="fd-step">
    Enable User Uploads [#1-enable-user-uploads]

    Go to `Startup` and set **User Uploaded Files** to `1`. This skips the Git clone step on startup.
  </div>

  <div className="fd-step">
    Upload Your Bot Files [#2-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.
  </div>

  <div className="fd-step">
    Set the Main File [#3-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.
  </div>

  <div className="fd-step">
    Configure Your Bot Token [#4-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](/docs/discord-bots/manage-bot-token) guide for more details.
  </div>

  <div className="fd-step">
    Start Your Server [#5-start-your-server]

    Go to the `Console` page and click **Start**. The server will automatically run `npm install` and then start your bot.
  </div>
</div>

Option B: Deploy from GitHub [#option-b-deploy-from-github]

<div className="fd-steps">
  <div className="fd-step">
    Set the Git Repository [#1-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)
  </div>

  <div className="fd-step">
    Set the Main File [#2-set-the-main-file]

    Set **Main File** to your bot's entry point (e.g., `index.js`).
  </div>

  <div className="fd-step">
    Enable Auto Update (Optional) [#3-enable-auto-update-optional]

    Set **Auto Update** to `1` if you want the server to pull the latest code from GitHub on each restart.
  </div>

  <div className="fd-step">
    Start Your Server [#4-start-your-server]

    Go to `Console` and click **Start**. The server will clone the repo, install dependencies, and run your bot.
  </div>

  <div className="fd-step">
    Configure Your Bot Token [#5-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.
  </div>
</div>

Installing Additional Packages [#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 [#using-a-private-github-repository]

On the `Startup` page, fill in the **Git Username** and **Git Access Token** fields. Create a [personal access token](https://github.com/settings/tokens) with `repo` scope and use it as the access token.

***

Discord Bot Server [#discord-bot-server]

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

<div className="fd-steps">
  <div className="fd-step">
    Upload Your Bot Files [#1-upload-your-bot-files]

    Log in to the [XGamingServer panel](https://panel.xgamingserver.com) 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.
  </div>

  <div className="fd-step">
    Install Dependencies [#2-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.
  </div>

  <div className="fd-step">
    Configure Your Bot Token [#3-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](/docs/discord-bots/manage-bot-token) guide for more details.
  </div>

  <div className="fd-step">
    Set the Startup Command [#4-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.
  </div>

  <div className="fd-step">
    Start Your Server [#5-start-your-server-1]

    Go to the `Console` page and click **Restart**. Your bot should come online and connect to Discord.
  </div>
</div>

Installing Additional Packages [#installing-additional-packages-1]

If you need to add more npm packages later:

<div className="fd-steps">
  <div className="fd-step">
    Switch to Bash [#1-switch-to-bash]

    Set the **Startup Command** to `/bin/bash` and restart.
  </div>

  <div className="fd-step">
    Install the Package [#2-install-the-package]

    In the `Console`, run:

    ```
    npm install package-name
    ```
  </div>

  <div className="fd-step">
    Switch Back [#3-switch-back]

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

    ***
  </div>
</div>

Troubleshooting [#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](https://discord.xgamingserver.com) 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.
