Use PM2, typescript for Heroku

Please help, how configure pm2 with watcher changes files and restart after crush?
Old config used nodemon.

package.json

{
  "name": "test-server",
  "version": "0.0.1",
  "description": "test server",
  "main": "index.js",
  "scripts": {
    "start": "nodemon -L --exec ts-node src/index.ts",
    "build-ts": "tsc",
    "postinstall": "npm run build-ts"
  },
  "engines": {
    "node": "8.9.1"
  },
  "author": "test",
  "license": "ISC",
  "dependencies": {
    "express-basic-auth": "^1.1.6",
    "@colyseus/monitor": "^0.1.11",
    "colyseus": "^0.9.28",
    "cors": "^2.8.5",
    "express": "^4.16.4",
    "nodemon": "^1.18.9"
  },
  "devDependencies": {
    "@types/express": "^4.16.0",
    "@types/node": "^10.12.18",
    "ts-node": "^8.0.1",
    "typescript": "^3.2.4"
  }
}

tsconfig.json

{
    "compilerOptions": {
        "outDir": "lib",
        "module": "commonjs",
        "lib": ["es6"],
        "target": "es2016",
        "declaration": true,
        "noImplicitAny": false,
        "experimentalDecorators": true,
        "sourceMap": true,
    },
    "include": [
      "**/*.ts"
    ]
}

Thanks for help

We are also facing same issue, other projects is working fine but colyseus isn't working fine. Looking forward to seeing your assistance @endel

"scripts": {
    "start": "ts-node index.ts",
    "bundle-colyseus-client": "browserify ./node_modules/colyseus.js/lib/index.js -s Colyseus -o static/colyseus.js",
    "build": "npm run bundle-colyseus-client",
    "heroku-postbuild": "npm run build"
  }, 

Please check the below link too.
https://stackoverflow.com/questions/54767053/nodejs-server-doesnt-start-with-pm2/54786719#54786719

Hey @daimonkor,

I think there's some confusion here. Heroku handles all this for you without the need for PM2 or nodemon.

I see you have nodemon in your package.json. Nodemon is not supposed to be used in production, and by default it does not restart automatically after a crash - it expects you to change a file and then it will restart. So, during development, you see you've made some mistake, you fix it, and the server will restart automatically when a file has changed.

If you do want to restart nodemon after crash anyway, there's this suggestion you can follow: https://github.com/remy/nodemon/issues/1221#issuecomment-356747303

For PM2 (which should not be used along with nodemon), you can use the --watch argument to restart when a file change occurs. I'd suggest configuring an ecosystem.config.js file with watch: true if you're using PM2: http://pm2.keymetrics.io/docs/usage/application-declaration/

Hope this helps. Cheers

When deploying your application on any platform, is not recommended to use the TypeScript files. You should use the compiled JavaScript files. (tsc -p tsconfig.json)

This post is deleted!

@endel Thanks for help, I found heroku dyno listen process on change and crush