continuous deployment with PM2

I have a series of .js configuration files for my Node application. Each describe a collection of data sources and runtime parameters. None of this is containerized yet.

The following is an excerpt from my ecosystem.config.js in my project root based on

module.exports = {
  apps: [{
    env: {
      NODE_ENV: 'production',
    name: 'myApplication',
    script: 'dist/server.js',
  deploy: {
    cs: {
      env: {
        NODE_ENV: 'production',
      host: [''],
      key: 'user1_at_host1.pem',
      path: '/home/myApplication/instance1',
      ref: 'origin/master',
      repo: '',
      ssh_options: 'StrictHostKeyChecking=no',
      user: 'user1',
      'post-deploy': 'app/ app/configs/instance1.js 3001 && cd app && npm install && npm run build && ./ cs && git checkout .',

The file wraps sed --expression=s/baseSettings:/host:\'$2\',port:$3,baseSettings:/ $1 > app/config.js to configure the listen host and port on a particular running instance. wraps a hard reset of the single-instance Node server (no hot deploys)

appList=`./node_modules/pm2/bin/pm2 ls`
if [[ ${appList} == *$1* ]]; then
  ./node_modules/pm2/bin/pm2 delete $1
./node_modules/pm2/bin/pm2 start dist/server.js -i 1 --name $1

At this point it is possible to hook up Jenkins to run ./node_modules/pm2/bin/pm2 deploy [environment name] origin/master