简体   繁体   English

NodeJS服务器不是以pm2开头

[英]NodeJS server doesn't start with pm2

When I'm trying to start my nodeJS-server with pm2 it stops or returns an error. 当我尝试使用pm2启动我的nodeJS服务器时,它将停止或返回错误。

Here's the relevant package.json file: 这是相关的package.json文件:

"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 npm -- start STOP
  • pm2 start index.ts ERROR pm2 start index.ts 错误

you trying to run ts file with ts-node. 您尝试使用ts-node运行ts文件。 try to install typescript in pm2 尝试在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: 如果您将PM2用作模块,则文档说要在package.json启动脚本上添加以下脚本:

"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 来源: https : //pm2.io/doc/en/runtime/integration/heroku/#add-pm2-as-a-module

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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