Registering Nodejs programs for Windows Services __js

Source: Internet
Author: User

Before I ran the Nodejs program, it was in the cmd command to enter a similar command to start:

Node D:\NodeJs\demo_express\microblog\app.js

The Nodejs program closes automatically when the cmd command is closed. In the production environment (development, debugger), this method can fully meet the requirements, but in the publishing environment, it is best to configure the service, so as to avoid the server restart, Windows illegal shutdown and other causes of bad results.

Here are two solutions I've tried: 1. Save the cmd command in a bat file and add the bat file to the program-> startup Advantages: Simple to implement, easy to understand. Disadvantages: Although the server restart after the Nodejs can start, but because there is a CMD command window running, if people illegally shut down, the NODEJS program will automatically shut down, so this method is not a cure. 2.windows Service Way Advantages: Not afraid of restarting, there is no cmd command Window disadvantage: the implementation of relatively complex, not too easy to understand

Implementation steps:

1> Create a new bat file with a file name of Run.bat, enter node D:\NodeJs\demo_express\microblog\app.js (the command modifies itself as appropriate) and save

2> Create a new service, refer to registering the Node.js program as a Windows service, and configure the Application property in step 5th to the path where the bat file resides


3. Find the service in the Windows Services list, make sure the startup type is automatic, then click Start and find no cmd command box. After you try to log off of your computer, you will find that the service is starting normally and the Nodejs program is running correctly. Since then, the service configuration has been successful


Note: For the operation of Step 2, if you have any questions, please leave a message

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.