Overview
In this article, we will explain how to setup your VPS to host a Discord.JS Bot. This article is based on Ubuntu 20.04, however the same steps should work for Ubuntu 18.04.

Server Prep & Connection
First, you need to ensure that your server is running either Ubuntu 20.04 or Ubuntu 18.04. If your server is not running this operating system, you can change it in your VPS Control Panel.
Next, login via SSH to your server. We have an article on how to access your server using SSH here: https://help.slashy.host/en/article/how-to-connect-to-a-vps-5wcqzs/

Updating Packages
Next, you want to update your VPS using the command sudo apt-get update Followed by sudo apt-get upgrade

Installing Node JS & NPM
Run the following command to install Node.JS sudo apt install nodejs
Please Note: This may not be the latest version of Node.JS, if you require a specific Node.JS version you will need to consult a guide online.
You can verify that Node.JS was installed by running node -version, and you should receive the version that Node.JS is currently running
Next, install the Node Package Manager (NPM) using the command sudo apt install npm.
Again, you can verify that NPM has been installed by running npm -version

Creating a folder for your bot & uploading bot files.
We recommend creating a folder for your bot inside of your /home/ folder. To navigate here, use the command cd /home/
Now, you will need to create a folder for your Discord Bot by using the command mkdir <folder name>
You will now want to navigate to your new folder using the command cd <folder name> - Replace <folder name> with the name of the folder that you created.
Using an SFTP program such as FileZilla, log into your server just like you would log into an FTP server, but set the port to 22. The credentials will be the same credentials that you use to access your SSH.
Once you have connected via SFTP, navigate to your newly created folder and upload all of your Discord.JS bot files.

Installing Packages
Providing that you have uploaded your files correctly, you should be able to navigate back to your SSH session and run npm install. This will read all of your required packages in your package.json file, and install them to your directory. If you haven’t got one already, this will also create a new folder called node_modules.
Once you have installed all of your NPM packages, you will need a service that can run your Node.JS app permanently without stopping unexpectedly. We recommend PM2 for this job, and you can install it by using the command npm install pm2 -g

Starting your Discord Bot
To start your Discord Bot, you can run the command pm2 start (main file), usually (main file) will be either index.js or app.js, you can find your starting file by running ls and looking out for the .js file.

Control your Discord Bot Status
- You can stop your service at anytime using the command pm2 stop (main file)
- You can restart your service at anytime using the command pm2 restart (main file)

Conclusion
And that’s it! You have added your Discord Bot to your VPS, and started it using PM2. Let us know if you found this article helpful using the selection below.
Was this article helpful?
Cancel
Thank you!