新人学习node.js中,在本地环境下做的demo,想放在自己服务器上搞
之前在本地,每次都有在命令行用node命令启动服务器,比如:
node server.js
现在放到了自己的腾讯云服务器上,难道每次都要先用node命令启动一下才能查看吗?
怎么做到用户自己访问网页的时候就自行起这个node服务器?
求解~
PHPz2017-04-17 15:27:34
It is recommended to use the process managerpm2
. For usage methods, please refer to the PM2 Practical Getting Started Guide summarized by the author before
Complicated operation: slightly
Poor service robustness: For example, if the program runs incorrectly, the server will hang up, and users will not be able to access it. At the very least, it needs to support automatic restart.
Other hidden dangers: After updating the service, such as modifying the configuration, etc., manual restart is required every time. Worse yet, you may simply forget to restart.
Solve the above problem.
It is very simple to use, first install pm2
npm install -g pm2
Then use pm2
to start the program instead. --watch
means monitoring the running status of the program. Once:
Service exception: automatic restart
Service changes: automatic restart
Others
pm2 start server.js --watch
黄舟2017-04-17 15:27:34
It should not start when the user accesses it, but the server should always be started
You can take a look at forever or pm2
巴扎黑2017-04-17 15:27:34
Recommendedpm2
, supports watch automatic restart, automatic restart when memory limit is exceeded, scheduled restart, cluster, log capture, etc. It is still very convenient