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