简体   繁体   English

将pm2与pkg一起使用

[英]Use pm2 with pkg

I have taken help from this site and created a .exe (an executable) for my node app. 我已从此站点获取帮助,并为我的节点应用程序创建了.exe (可执行文件)。 But, in case of some errors, it just vanishes. 但是,如果出现一些错误,它就消失了。 I used to get on with it by using pm2 , but now that I need to use an executable, I have used pkg , to create its .exe file. 我以前使用pm2 ,但是现在我需要使用一个可执行文件,我已经使用pkg来创建其.exe文件。

Is there a way to run this using pm2 just on double clicking it? 有没有一种方法可以通过双击pm2来运行它?

I don't think that you can stop a top level error from closing the running program. 我认为您无法停止正在运行的程序的顶级错误。 It's more a OS feature than a nodeJS one. 它比nodeJS具有更多的操作系统功能。

You will need to catch all errors and manage them properly. 您将需要捕获所有错误并正确管理它们。

The easier way to do that (but not the cleanest) would be wrap the entry point in a try catch function and relaunch it from the catch when an error arise. 这样做的更简单方法(但不是最干净的方法)是将入口点包装在try catch函数中,并在出现错误时从catch重新启动它。

Hi as per my knowledge PM2 restarts once it encounters errors, there is also a way to watch for changes in the folder structure. 嗨,据我所知,一旦PM2遇到错误,它就会重新启动,还有一种方法可以监视文件夹结构的变化。 Once there is an error and your server is about to restart at that particular time use the package to build the .exe file and then start the server. 一旦出现错误,并且服务器将在该特定时间重新启动,请使用该软件包生成.exe文件,然后启动服务器。

In the following, if you want to pass any arguments then use --node-args else don't use 在下面的内容中,如果要传递任何参数,请使用--node-args,否则不要使用

pm2 start app.js --name "You App Name" --node-args="-r dotenv/config" --watch

And then in your app.js file do the following 然后在您的app.js文件中执行以下操作

const pkg = require('pkg');

//here use the package to build the .exe file

//here start the server

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

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