All the steps required to deploy Nesula on a node app server
Note: we will be using Linux user 'ifactory' with DNS entries for nesula.ifactory.co and ... to ths server.
1. Pre-Steps
Have a Node Server prebuilt - see the other setup docs.
2. Create Folder
$ mkdir /var/www/nesula.ifactory.co
$ cd /var/www/nesula.ifactory.co
3. Install Nesula Repository
$ git init
$ git clone https://github.com/iFactoryDigital/Nesula.git [ When prompted enter Github username & password ]
New Github Clone Method
Create an SSH Key and add to your account. Note Github.com only excepts OpenSSH key's. To convert your PuttyGen my-ssh-key.pub ceate a new file my-ssh-key.open-ssh.pub and add the following:
ssh-rsa
TBC - SSH is too much bother while clone https:// still functions
4. Download Dependencies
$ cd Nesula [ enter working directory ]
NestJS Dependencies
$ cd /var/www/nesula.ifactory.co/Nesula/nest-api
$ npm install
Angular Dependencies
$ cd /var/www/nesula.ifactory.co/Nesula//angular-app
$ npm install
6. Database and ORM Config
If you are using Postgres on this server then ensure a staging or production database has been created e.g. 'nesula_stage'
Rename the existing ormconfig.json to ormconfig-dev.json
Create a new ormconfig.json for the stage/prod environment and update with correct host, username, password and database.
5. Build App
$ cd /var/www/nesula.ifactory.co/Nesula/nest-api
$ npm run build
$ cd /var/www/nesula.ifactory.co/Nesula//angular-app
$ npm run build
$ npm run start:prod
$ pm2 startup [ Generate an active startup script to restart current processes ]
7. Monitor App Performance - OPTIONAL
$ ps ax | grep node [ If run with node - list all node processes ]
$ pm2 monit [ If run with PM2 - Displays the PM2 real-time monitoring UI ]
$ htop [ Display real-time per CPU usage and active processes ]
8. Environment Variables, config & NODE_ENV
It is import to correctly set the NODE_ENV environment variable.
Nesula makes use of the NestJS ConfigModule and ConfigService. ConfigService imports the following config files:
The configuraiton.ts file values can either be populated by values from the .env file or if they are not environment specific hard coded directly.
Environment variables are available in configuration.ts as follows:
{
...
app-var: process.env.NES_APP_VAR [ NES_APP_VAR is from .env file ]
app-name: 'App-name' [ value hardcoded in file ]
}
Nesula has four config files:
.env [ ONLY environment file imported by Nesula ConfigService ]
.env.development [ development environment config ]
.env.test [ staging or test environment config ]
.env.production [ production environment config ]
Set config file for environment
To deploy a config file in a particular environment we replace the .env file. For Example in production:
To simplify this deployment step we have created the following commands:
# Defined in nest-api/package.json
$ npm run deploy:dev [ set .env to .env.development ]
$ npm run deploy:test [ set .env to .env.test ]
$ npm run deploy:prod [ set .env to .env.production ]
We can also manually set the process.env.NODE_ENV from the server environment variable at run time
To set NODE_ENV at the command line:
$ export NODE_ENV=stage [ set server environment variable 'NODE_ENV' to 'stage' ]
$ echo $NODE_ENV [ show value of environment variable ]
$ printenv [ show all environment variables ]
$ unset NODE_ENV [ Delete environemtn variable ]
9. Check DNS & Reverse DNS Settings
$ dig +short $URL [ check A Record with $URL Place holder ]
$ dig +short nesula.ifactory.co [ check A Record with actual domain address ]
$ dig -x $IP +short [ Check rDNS / reverse DNS of $IP ]
$ dig -x 172.105.161.59 +short [ Check rDNS / reverse DNS for actual IP address ]