Skip to content

[Server] Install and Running Guide

Hyeonwoo Kim edited this page May 31, 2022 · 50 revisions

Summary

Here, we explain how to deploy a baetaverse server

The following commands must be executed on the computer that will be used as the server.

Using Docker

Docker install guide (link)

Download Dockerfile

Download Dockerfile from here

or

Clone BAETAVERSE project

# In your work directory
git clone https://github.com/kookmin-sw/capstone-2022-43.git
cd ./capstone-2022-43

Build Dockerfile to docker image

# In Dockerfile located path
# Should needs sudo option

docker build -t <your docker image name> .

Run docker image

docker images
docker run -dit \
           -p <YOUR ACCESS SERVER PORT NUMBER>:<YOUR SERVER PORT NUMBER IN CONTAINER> \
           --name <YOUR DOCKER CONTAINER NAME> \
           <YOUR DOCKER IMAGE NAME>

Execute docker container

docker ps
docker exec -it <YOUR DOCKER CONTAINER NAME OR ID> bash
# Print simple server guide
cat README.txt

Configure .env file

vi .env
PORT=_your_port_number_
JWT_OWNER_SECRET=_your_jwt_owner_secret_key_
JWT_FORWARDER_SECRET=_your_jwt_forwarder_secret_key_
HSCODE_SERVER_HOST=_your_hscode_server_host_url_
MYSQL_SERVER_HOST=_your_database_server_host_
MYSQL_SERVER_PORT=_your_database_server_port_numaber_
MYSQL_SERVER_USER=_your_database_access_user_name_
MYSQL_SERVER_PASSWORD=_your_database_access_user_password_
MYSQL_SERVER_DATABASE=_your_database_name_

If you done previous processes

Go on Build and Run Server

Install on Local machine

Install node.js

Windows

Go to the Node.js Website and Download current Windows version.

macOS

brew install node

Linux

sudo apt-get update
sudo apt-get install -y build-essential
sudo apt-get install curl
curl -sL https://deb.nodesource.com/setup_17.x | sudo -E bash --
sudo apt-get install -y nodejs

Check the npm (Node Package Manager) and node.js version

npm -v  //8.5.5
node -v  //v17.8.0

Install BAETAVERSE project

# In your work directory

git clone https://github.com/kookmin-sw/capstone-2022-43.git
cd ./capstone-2022-43/server

Add .env file

Add your application configuration to your .env file in the capstone-2022-43/server

PORT=_your_port_number_
JWT_OWNER_SECRET=_your_jwt_owner_secret_key_
JWT_FORWARDER_SECRET=_your_jwt_forwarder_secret_key_
HSCODE_SERVER_HOST=_your_hscode_server_host_url_
MYSQL_SERVER_HOST=_your_database_server_host_
MYSQL_SERVER_PORT=_your_database_server_port_numaber_
MYSQL_SERVER_USER=_your_database_access_user_name_
MYSQL_SERVER_PASSWORD=_your_database_access_user_password_
MYSQL_SERVER_DATABASE=_your_database_name_

Build and Run server

Build the Server source codes

  • Install node package Dependency
# For local machine
# Unnecessary process If you use docker image

npm install
  • Build source files
# Build typescript files using tsc
# Create javascript files in 'dist' directory

npm run build

Execute Server

  • Start with standard node command (Not recommended)
npm start

Ctrl+C # Stop server
  • Start with nodemon package (For development)
# Unnecessary build process
# Run directly with typescript files

npm run dev

Ctrl+C # Stop server
  • Start with PM2 (Recommended)
# For local machine
# Unnecessary process If you use docker image

npm install -g pm2
npm run deploy

pm2 stop server # Stop server

Monitoring server log

Server logs save in logs directory as a file about one day

If you want to know server logs about real time

We recommend to use PM2

# See logs in terminal
pm2 log

example image image



# Trace logs with process information (ex. Memory usage, Heap size etc)
pm2 monit

example image image


PM2 also offer real time server logs on their websites

You can see about PM2 on pm2.io