GitHub Documentation

Use PM2, typescript for Heroku

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


      "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"


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

    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.

  • administrator

    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:

    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:

    Hope this helps. Cheers

  • administrator

    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)

  • gladiator

    This post is deleted!

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


© 2021 Lucid Sight, Inc