Deploy: Production

Deploying changes to production environment

$ cd /var/www/prod.nesula.com/nesula

Pull From Github

This will subject to your Git branch workflow

$ git checkout master [ Assumes Production code is on master branch ]
$ git pull      

Angular

$ cd /var/www/prod.nesula.com/nesula/angular-app
$ npm install         [ OPTIONAL: Install or update any new npm packages listed in package.json ]
$ npm run start:prod   [ Build angular javascript for dev environment ]

The start:prod command does the following:

  1. Set the Angular .env file to production

  2. Run ng build to compile files in an angular default development mode

  3. Start angular server by default on port 4200

NestJS


$ cd /var/www/prod.nesula.com/nesula/nest-api
$ npm install        [ OPTIONAL: Install or update any new npm packages lsited in package.json ]
$ npm run build      [ Delete / dist & build angular javascript ]
$ npm run start:dev  [ Starts NestJS node app with pm2 in prod mode ]

The NestJS NPM start:prod command does the following:

  1. Set NestJS .env file to production

  2. Delete the /dist folder

  3. Delete the log file

  4. Build application files in the /dist folder

  5. Copy handlebar email templates used by NestJS server pages to /dist folder

  6. Launch the app with pm2 server

Database Migration

In development and staging environemenrs TypeORM will automatically sync the database schema with any changes to entities on deployment. However in production application this can be dangerous as the changes cannot be undone. Nesula by default does not sync in production as defined the config file. Database migrations will have to be run manually.

.env.prod
# ----- TYPEORM -----
NES_TYPEORM_SYNCHRONIZE = "false"
NES_TYPEORM_MIGRATIONS_RUN = "true"

Generating & Running Migrations

$ cd /var/www/prod.nesula.com/nesula/nest-api  [ Commands in NestJS package.josn ]

$ npm run mig:generate   [ Create migrations in /src/migrations ]

$ npm run mig:run        [ Run migrations in migrations folder ]

Revert Migrations

To undo changes made to the database user revert:

$ npm run mig:revert

Migrations make use of the TypeORM command line interface (CLI) which is a different instance of TypeORM connection manager. Its configuration is found in:

nest-api/src/ormconfig-cli.ts

Last updated

Was this helpful?