[英]How to run pm2 with node.js ts on debug mode and break on WebStorm
[英]Not able to run typescript node.js app with ts-node with pm2
我创建了一个带有打字稿顶部的基本节点应用程序。 我正在使用 ts-node 这样做,它与 nodemon 一起工作得很好。 但是现在我卡住了,我需要将它移到服务器上。 PM2一直显示错误。 我已经浏览了 GitHub 和 StackOverflow 上的其他答案。 这里没有任何帮助。 请帮忙。
我试过用 PM2 安装 typescript 和 ts-node。 但它对我不起作用。 我也试过直接运行文件,没有用。 我现在不知道该怎么解决这个问题。
"scripts": {
"start": "nodemon -x ts-node src/server.ts"
},
它适用于简单的 npm run start 命令
madbo@DESKTOP-CS5UFKE MINGW64 /e/shailesh/nodejs/NodeType
$ npm run start
> NodeType@1.0.0 start E:\shailesh\nodejs\NodeType
> nodemon -x ts-node src/server.ts
[nodemon] 1.18.5
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `ts-node src/server.ts`
24 Mar 22:33:23 - listening on port 3000
Mongoose default connection is open to mongodb://localhost:27017/todo 😍
到目前为止我尝试过的没有用*(PM2 是全局安装的)*
pm2 start ts-node -- --type-check -r tsconfig-paths/register src/server.ts
它给了我这个错误
madbo@DESKTOP-CS5UFKE MINGW64 /e/shailesh/nodejs/NodeType
$ pm2 start ts-node -- --type-check -r tsconfig-paths/register src/server.ts
[PM2][ERROR] script not found : E:\shailesh\nodejs\NodeType\ts-node
script not found : E:\shailesh\nodejs\NodeType\ts-node
┌──────────┬────┬─────────┬──────┬─────┬────────┬─────────┬────────┬─────┬─────┬──────┬──────────┐
│ App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
└──────────┴────┴─────────┴──────┴─────┴────────┴─────────┴────────┴─────┴─────┴──────┴──────────┘
Use `pm2 show <id|name>` to get more details about an app
我还使用了以下
pm2 start npm -- ts-node src/server.ts
并得到
$ pm2 start npm -- ts-node src/server.ts
[PM2] Applying action restartProcessId on app [npm](ids: 0)
[PM2] [npm](0) ✓
[PM2] Process successfully started
┌──────────┬────┬─────────┬──────┬───────┬────────┬─────────┬────────┬─────┬───────────┬───────┬──────────┐
│ App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
├──────────┼────┼─────────┼──────┼───────┼────────┼─────────┼────────┼─────┼───────────┼───────┼──────────┤
│ npm │ 0 │ N/A │ fork │ 11300 │ online │ 15 │ 0s │ 0% │ 21.5 MB │ madbo │ disabled │
└──────────┴────┴─────────┴──────┴───────┴────────┴─────────┴────────┴─────┴───────────┴───────┴──────────┘
Use `pm2 show <id|name>` to get more details about an app
madbo@DESKTOP-CS5UFKE MINGW64 /e/shailesh/nodejs/NodeType
$ pm2 status
┌──────────┬────┬─────────┬──────┬─────┬─────────┬─────────┬────────┬─────┬────────┬───────┬──────────┐
│ App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
├──────────┼────┼─────────┼──────┼─────┼─────────┼─────────┼────────┼─────┼────────┼───────┼──────────┤
│ npm │ 0 │ N/A │ fork │ 868 │ stopped │ 24 │ 0 │ 0% │ 0 B │ madbo │ disabled │
└──────────┴────┴─────────┴──────┴─────┴─────────┴─────────┴────────┴─────┴────────┴───────┴──────────┘
Use `pm2 show <id|name>` to get more details about an app
请帮我解决这个问题
我希望它在服务器上使用 pm2 的服务器上工作。 如果你们中的任何人都可以解决我的问题,我将非常满意。 谢谢
这是非常简单的家伙。
只需将tsc
和pm2
watch 与单个&
结合使用即可运行这两个命令。
"scripts": {
"serve": "tsc src/app.ts -w & pm2 start dist/app.js --watch"
},
创建一个文件 run-ts.sh
ts-node -T index.ts
运行这个命令
pm2 start run-ts.sh
这样你就可以运行你的 Typescript 应用程序了🚀
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.