-
Notifications
You must be signed in to change notification settings - Fork 18
DigitalOcean nodeGame From Scratch
Please create an account on Digital Ocean using this referral link: https://m.do.co/c/77e0cad8a86b.
You will get 100USD credit to spend during the first two 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).
-
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 this guide.
-
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 this Nginx setup file 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.