Cloud Server Installation
Follow these steps to create a server and host the lobby server and/or the game server.
In this example, we are going to use Digital Ocean, but the server application can be hosted on any cloud provider of your choice.
If you do not have an account already, you can use this referral link to create an account, and the first two months will be free.
https://m.do.co/c/ca46a35fd4dd
Prerequisites
You will need to download these two applications in order to access your server. One is a SFTP file manager and the other is a SSH command line tool. These tools are for Windows, but there are plenty of SFTP and SSH alternatives on Mac/Linux.
WinSCP: https://winscp.net/eng/index.php
Putty: https://www.putty.org/
When installing Putty, make sure to also install PuttyGen (it is to generate ssh keys).
Create a Droplet
After you created a Digital Ocean account and entered your credit card information, and that your account is ready to use, you are ready to create a Droplet.
1) In Droplets section, click on Create -> Droplet
2) Select the OS: I use Ubuntu 22.04
3) Choose the specs of your server
I recommend 2+ CPU. (For dev the $20 server should be more than enough, but if you have a lot of players, you will probably need to upgrade that later.)
4) Choose any region (closest to you will have better performances).
5) Select a SSH key (see next section to generate a new one)
6) Select a hostname for your server (can be anything).
7) Click Create Droplet
Once your droplet is ready, the IP of your server will be displayed. You will need that IP later when creating the unity build.
Generate SSH key with PuttyGen
To generate a key, open PuttyGen and click on generate.
Once done, save the private key file on your computer.
Then copy the public key displayed on screen to Digital Ocean.
On Digital Ocean, Add a name to your key and then click on Add SSH key.
Make sure to store your private key file in a secure place, if you lose the key you won’t be able to access your droplet.
Connect to your server with WinSCP
Open WinSCP and create a new connection.
Enter the IP of your server as Host, and enter Root as the username.
The password is blank since we use a SSH key instead.
Click on Advanced, then SSH/Authentication, then select your private key file there.
This will give you access to the server files
You can unzip and upload the NodeJS code into any folder. In my demo I created this folder and uploaded all the JS code there.
/server/api
To access the command line, from WinSCP, click on Commands->Open in Putty.
Once you gain access you can navigate to the server folder with
cd /server/api
Install MongoDB
Follow the instruction to install MongoDB
https://www.digitalocean.com/community/tutorials/how-to-install-mongodb-on-ubuntu-20-04
If you get an error about libssl, check this to resolve it:
Start Mongo with
And make sure it is working correctly
Open mongo command line with
While mongo is running in the command line prompt, you can run mongo commands. Use this one to change to the admin database to manage users
Run these command to add mongo users. Make sure to set a different password for each, save them somewhere to use later, and note the database name (in this example its called userdb).
Important: Mongo Users are not the same than your actual users in the database. You don't need a mongo user for each real user. Mongo users are just a list of apps credentials who can connect to mongo. I usually only create 3 users, not more. One root user, one for the NodeJS app, and one read-only user to use in mongo compass.
Create a Root user
Create a user for your app
And finally I also like to create a read-only user
If you made a mistake you can delete a user with
Use Ctrl-C at anytime to quit mongo and return to regular ubuntu command line.
Install NodeJS and NPM
Run this to install NodeJS and NPM
Install forever globally to run NodeJS as a service
Install node modules for the User API app
In WinSCP, open the config.js file to edit a few things
Change mongo_user to "api" (or any other mongo user you created for your app)
Change mongo_pass to the password your set for your api user
Change jwt_secret to any random value
In command line, try to run the app to see if it is working
If there are no error message, this means the app is working! Use ctrl-c to quit the app.
Run NodeJS as a service
You can use forever to run NodeJS as a service so it stays on when you close the command line window
When you make any changes, or reupload the app, you can restart with
You can also check if it is running properly
Last updated