What is the best practise to deploy Node app with Github Runner (Self hosted)

Hi folks,

I’ve using GitHub runner (self-hosting) for deploying the Node.js app. Before the building of the runner, it removes all folders, files on the server and creating a new build folder. So, that means the server stops while the runner building. I don’t want to interrupt my running server.

My question is, what is the best practice of node deploying?

Should I copy the build files to another folder in yml file?

Here is the yml file:

name: Node.js CI

on:
  push:
    branches: [staging]
  pull_request:
    branches: [staging]

jobs:
  build:
    runs-on: self-hosted
    defaults:
      run:
        working-directory: ./server
    strategy:
      matrix:
        node-version: [14.x]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    steps:
      - uses: actions/checkout@v2
      - name: Creating env file
        run: |
          touch .env
          echo NGINX_URL=${{ secrets.NGINX_URL_STAGING }} >> .env
          echo PUBLIC_URL=${{ secrets.PUBLIC_URL_STAGING }} >> .env
          echo HOST=${{ secrets.HOST }} >> .env
          echo ADMIN_JWT_SECRET=${{ secrets.ADMIN_JWT_SECRET_STAGING }} >> .env
          echo DATABASE_PASSWORD=${{ secrets.DATABASE_PASSWORD_STAGING }} >> .env
          echo DATABASE_USERNAME=${{ secrets.DATABASE_USERNAME_STAGING }} >> .env
          echo DATABASE_NAME=${{ secrets.DATABASE_NAME_STAGING }} >> .env
          echo DATABASE_PORT=${{ secrets.DATABASE_PORT_STAGING }} >> .env
          echo DATABASE_HOST=${{ secrets.DATABASE_HOST_STAGING }} >> .env
          echo DATABASE_SSL=${{ secrets.DATABASE_SSL_STAGING }} >> .env
          echo NODE_ENV=${{ secrets.NODE_ENV_STAGING }} >> .env
          cat .env
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v2
        with:
          node-version: ${{ matrix.node-version }}
      - name: Install dependencies
        run: yarn
      - name: Building
        run: yarn build
      - name: Restart server
        run: pm2 restart aj-staging