-
Notifications
You must be signed in to change notification settings - Fork 18
nodeGame on DigitalOcean
Please create an account on Digital Ocean using this referral link: https://m.do.co/c/77e0cad8a86b.
You will get 50USD credit to spend during the first month and you will also contribute to cover nodeGame's hosting expenses at no extra costs for you (please notify us if the amount of credit is different).
After registered, you can create a new Digital Ocean server ("droplet") for nodeGame with just a few clicks using the Marketplace app. On the side menu on the right, under the Discover header, click on Marketplace, then type nodeGame in the search box.
In the next page, select "Create NodeGame Droplet."
Next, you need to specify your droplet's settings. If unsure, you can follow the guidelines below.
-
Choose the cheapest Droplet (5USD per month). Remember, you will be charged only for the time you actually use it. For instance, if you use it for one day and then dispose it, you will be charged approximately 16 cents.
-
Choose the hosting data center according to your targeted population. For instance, If you plan to mainly reach an American audience, you could pick the NYC data center.
-
Add additional services, such as backup, as needed (extra charges may occur).
-
Choose if you want to use a password or a SSH key to login into your Droplet. Using a password requires no additional configuration, but using an SSH key is safer and faster. If you decide to go for the SSH key please follow the steps below.
-
SSH (Secure SHell) keys are a way to establish a fast and secure authentication between two computers.
-
Verify if you already have a SSH key on your computer (if you never heard of SSH keys before, you probably don't have one). Open a terminal (e.g., Git Bash) and type:
cd; cat .ssh/id_rsa.pub
.(where
cd;
makes sure you are inside your home directory, andcat
prints the content of the file to the terminal).If you see a long sequence of random characters and numbers, congratulations that is your public SSH key and you can jump to Step 5.
-
If you get a file-not-found error, you need to create a new SSH key with ssh-keygen. Type:
ssh-keygen.exe
in Windows orssh-keygen
in Linux and Mac.Press enter until the process of creation is completed, and you can leave blank any question on the prompt.
-
Repeat Step 2 and output the public key to your terminal.
-
Copy the public key from the terminal (if you don't know how to copy it, you can open it in your default text editor with the command:
cd; start .ssh/id_rsa.pub
). Remember to include all characters. -
Go to Digital Ocean and add your public key. This procedure may vary in the future, but here are the current steps:
- Click on the top-right icon with your name and select "Account" from the dropdown menu.
- Select the "Security" tab from the newly open panel.
- Click "Add SSH key"
-
Remember! SSH keys are tied to a specific computer. You will need to create a new SSH key and upload it to Digital Ocean for every computer you use to login into your Droplet.
Once created, you need to ssh into your droplet once to activate it. Open a terminal (e.g., Git Bash) and type:
ssh root@DROPLET_ADDRESS
(where DROPLET_ADDRESS
is the ip address of your droplet that you
can find in the dashboad).
If successful, you should see something like:
After you created your nodeGame droplet, you may upload your game
inside the games/
directory of the nodeGame server. You have two
options:
-
If your game is on an online git repository (e.g., GitHub): open a terminal (e.g., Git Bash) and login into your Droplet. Navigate to the
games/
folder inside the nodeGame installation directory and type:git clone GIT_ADDRESS
(where
GIT_ADDRESS
is the address of your git repository). -
If your game is on your local computer: open a terminal (e.g., Git Bash) and navigate to the
games/
folder inside your local nodegame installation directory and type:scp -r YOUR_GAME root@DROPLET_ADDRESS:nodegame-vXXX/games/
(where
YOUR_GAME
is the name of the directory containing your game,DROPLET_ADDRESS
is the address of your Droplet, andXXX
is the actual nodegame version number).
-
Stop the server:
pm2 stop launcher
-
Start your game as default:
pm2 start launcher.js -- --default YOUR_GAME
If you feel adventurous, you can manually install nodeGame from scratch.
-
Choose the Node.JS app Droplet from the Marketplace and follow the same steps as in the section "Droplet Setup" above.
-
From the dashboard, copy the IP address of your new Droplet from the Digital Ocean web site. It should look something like 167.134.32.47 (the actual numbers will be different).
-
Open a terminal (e.g., Git Bash) and login into your Droplet:
ssh root@DROPLET_ADDRESS
(where
DROPLET_ADDRESS
is the address copied at the previous step). -
Note! If you chose to authenticate yourself with a SSH key (section "Upload your SSH key"), you will be immediately logged in into your Droplet, otherwise you will be asked for a password.
-
Download the nodegame installer:
wget http://nodegame.org/nodegame-installer.js
. -
Install nodeGame:
node nodegame-installer.js @dev
.Note that the parameter
@dev
is optional and it will install the latest development version. For more install options:node nodegame-installer.js --help
. -
Enter the nodegame installation directory:
cd nodegame-vXXX
(where
XXX
is the actual nodeGame version number). -
Change nodeGame port from
8080
to80
, because port8080
is blocked by Digital Ocean:nano conf/servernode.js
and uncomment the line saying
servernode.port = 80;
Save the file (follow instruction at the bottom of the terminal).
-
Launch nodegame:
node launcher.js
and open your browser at:
http://DROPLET_ADDRESS
(no port necessary). -
Stop the nodeGame server with Ctrl-c in the terminal.
-
Remember! Your server is running only as long as you keep the SSH connection open. To avoid unexpected server's downtime, it is recommended to use a process manager, e.g.
pm2
. Check the section 'Install PM2' for details. -
Optional. You may want to install the Nginx server to handle all incoming connections. This can increase the reliability and robustness of your application. It also makes handling ssl certificate a bit easier. Check the section 'Install Nginx' for details.
-
pm2 is a free process manager, a program that will take care of keeping nodeGame always running. To install:
npm install pm2 -g
. -
Go to the nodegame installation directory and type:
pm2 start launcher.js
. -
To stop the server type:
pm2 stop launcher
. -
To restart your server:
pm2 restart launcher
. -
To see info about your server:
pm2 info launcher
.
Nginx is an open source web server known for its efficiency and robustness. You can put "in front" of nodeGame to handle all incoming connections. Technically this is called a reverse proxy to nodeGame. Here are the step to setup it.
-
Update the registry of applications with the command:
apt update
. -
Install Nginx with the command
apt install nginx
. -
Copy the setup file for nginx from this address and save it under the location:
/etc/nginx/sites-enabled/default
. -
Restart Nginx with the command:
systemctl restart nginx
. -
Nginx is now listening on port 80, so you need to make sure nodeGame is listening to another port. Let's pick 8080, or whatever you have specified in the nginx conf file. Inside the nodeGame root directory type:
nano conf/servernode.js
and set:
servernode.port = 8080;
-
Start nodeGame as usual and it will now receive all the incoming connections from Nginx.
Go back to the wiki Home.
Copyright (C) 2021 Stefano Balietti
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.