Skip to content

Production setup


These instructions are out of date. The information may no longer be accurate.

To put Node applications into production, they must run locally on a port blocked from the public via firewall (e.g. 8666) and then be reverse proxied to a suitable web port, such as port 443 via Apache configuration. Any reverse proxy web server will work. We use Apache, so the following examples will assume this setup.

PM2 Setup

To run the Node app on the production server:

  • Follow the development installation instructions as before.
  • Do npm run start:hecate file for Hecate and npm run start:goose for Goose. Configuration specific to those environments should go in the .env file on the respective server.

Apache Reverse Proxy Setup

  • Ensure the Apache has the proxy and proxy-http modules enabled

    • sudo a2enmod proxy
    • sudo a2enmod proxy-http
  • Configure your Apache server to reverse proxy the Node server you've started at the port you defined in the .env file.



ProxyRequests Off
ProxyPreserveHost On

<Proxy *>
  Order deny,allow
  Allow from all

ProxyPass /api <http://localhost:8666>
ProxyPassReverse /api <http://localhost:8666>
  • Restart Apache

    • sudo apachectl reload
    • sudo apachectl restart

Pre-Deployment checklist

  • Locally, update all packages with yarn upgrade, which updates all npm packages within the range specified in the package.json
  • Commit yarn.lock so that yarn install mirrors these exact packages on goose and hecate
  • To make sure that you haven't forgotten to add any new environment variables server, run ssh "cat ~/hakai-api/.env" | git diff - .env
  • git pull main on the server (goes without saying!)
  • If changes have been make to the repositoryhakai-upload-validator, make sure those changes have been merged to main
  • Likewise, for changes that affect the RSK2HakaiJSON matlab procedure in hakai-data-tools ( check with Jesse)

Docker Deployment

Run yarn run start:{hecate|goose}

Manual Deployment

To deploy on the server, run

  • yarn install
  • pm2 del hakai-api
  • pm2 start src/main.js

Push to deploy

** Note - these might need to be updated/revisited with instructions for setting up matlab above & updating hakai-data-tools **

This application has a Git push-to-deploy system set up on both Goose and Hecate. This system allows you to push to a Remote git repo, and when that Remote receives an updated copy of the application, it will run a scripts that installs new packages and restarts the running PM2 hakai-api process. Use this method to push new code into production.

On the servers you need to run this to make it work:

cd ~/hakai-data-portal-v2
git config receive.denyCurrentBranch ignore

To push to Goose:

  1. Add the Git remote url (first time) with git remote add goose
  2. Push the development branch to the Goose Git remote branch with git push goose development. You should see output from the script running on Goose that is deploying the app.

To push to Hecate:

  1. Add the Git remote url (first time) with git remote add hecate
  2. Push the main branch to the Hecate Git remote branch with git push hecate main. You should see output from the script running on Hecate that is deploying the app.

You can review your remotes with git remote -v

Git hooks

The scripts that run on Goose or Hecate to deploy the app can be found in hakai-api/githooks/post-receive.{goose|hecate}.

In order to use them on the server, they need to be copied to hakai-api/.git/hooks with the .goose or .hecate extension removed. The files also need to have executable permissions so you may need to run chmod +x post-receive.

Overview of hooks

Helpful issue discussion: 'husky not found' error when it appears to be installed