search

Home  >  Q&A  >  body text

【一个关于Node.js的小问题】服务器上如何启动node Server?

新人学习node.js中,在本地环境下做的demo,想放在自己服务器上搞
之前在本地,每次都有在命令行用node命令启动服务器,比如:

node server.js

现在放到了自己的腾讯云服务器上,难道每次都要先用node命令启动一下才能查看吗?
怎么做到用户自己访问网页的时候就自行起这个node服务器?

求解~

PHP中文网PHP中文网2783 days ago489

reply all(3)I'll reply

  • PHPz

    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

    Possible problems caused by the way the poster starts the service

    1. Complicated operation: slightly

    2. 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.

    3. 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.

    Reason for using pm2

    Solve the above problem.

    How to use

    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

    reply
    0
  • 黄舟

    黄舟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

    reply
    0
  • 巴扎黑

    巴扎黑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

    reply
    0
  • Cancelreply