DigitalOcean nodeGame From Scratch - nodeGame/nodegame GitHub Wiki

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).

Create a nodeGame Droplet from Scratch

Droplet Setup

  1. 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.

  2. 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.

  3. Add additional services, such as backup, as needed (extra charges may occur).

  4. 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.

nodeGame Setup

  1. 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).

  2. 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).

  3. 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.

  4. Download the nodegame installer:

    wget http://nodegame.org/nodegame-installer.js.

  5. 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.

  6. Enter the nodegame installation directory:

    cd nodegame-vXXX

    (where XXX is the actual nodeGame version number).

  7. Change nodeGame port from 8080 to 80, because port 8080 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).

  8. Launch nodegame:

    node launcher.js

    and open your browser at: http://DROPLET_ADDRESS (no port necessary).

  9. Stop the nodeGame server with Ctrl-c in the terminal.

  10. 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.

  11. 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.

Install PM2

  1. pm2 is a free process manager, a program that will take care of keeping nodeGame always running. To install: npm install pm2 -g.

  2. Go to the nodegame installation directory and type: pm2 start launcher.js.

  3. To stop the server type: pm2 stop launcher.

  4. To restart your server: pm2 restart launcher.

  5. To see info about your server: pm2 info launcher.

Install Nginx

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.

  1. Update the registry of applications with the command: apt update.

  2. Install Nginx with the command apt install nginx.

  3. Copy this Nginx setup file and save it under the location: /etc/nginx/sites-enabled/default.

  4. Restart Nginx with the command: systemctl restart nginx.

  5. 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;

  6. Start nodeGame as usual and it will now receive all the incoming connections from Nginx.

⚠️ **GitHub.com Fallback** ⚠️