[英]How can I host my NodeJS app “forever” without my computer being on?
On my website, I host an express app that hosts a different port than what is hosted by Namecheap, which is what I am using for hosting.在我的网站上,我托管了一个 Express 应用程序,该应用程序托管的端口与 Namecheap 托管的端口不同,这是我用于托管的端口。 Right now I'm just hosting the express app in the terminal in cPanel for testing, but when I release the site this way won't be acceptable.现在我只是在 cPanel 的终端中托管 express 应用程序进行测试,但是当我以这种方式发布网站时,这是不可接受的。
Is there a way I could host my express app without my computer always being on and hosting it manually?有没有一种方法可以托管我的 Express 应用程序,而无需我的计算机始终打开并手动托管它?
Install pm2 as global dependency in your hosting server.在您的托管服务器中安装 pm2 作为全局依赖项。
npm i pm2 -g
After that go to app directory and run.之后转到应用程序目录并运行。
pm2 start app.js --name "name of your app"
It will run your application forever until some error may not occur.它将永远运行您的应用程序,直到可能不会发生某些错误。
您可以构建应用程序的 docker 映像并永远运行 docker 容器,或者使用 pm2 或永远等进程管理器以分离模式运行您的应用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.