简体   繁体   中英

NodeJS server doesn't start with pm2

When I'm trying to start my nodeJS-server with pm2 it stops or returns an error.

Here's the relevant package.json file:

"scripts": {
"start": "nodemon --watch '**/*.ts' --exec 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"}

I tried the following commands to start the server:

  • pm2 start npm -- start STOP
  • pm2 start index.ts ERROR

you trying to run ts file with ts-node. try to install typescript in pm2

pm2 install typescript

and then the second command

pm2 start index.ts

您的服务器可能正在与nodemon一起运行,我想首先通过从nodemon退出来停止服务器,然后启动pm2,然后它应该可以工作

If you're using PM2 as a module, the documentation says to add the following script on your package.json start script:

"scripts": {
    "start": "pm2-runtime start ecosystem.config.js --env production"
},

Now you can restart your application.
Source: https://pm2.io/doc/en/runtime/integration/heroku/#add-pm2-as-a-module

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM