Register the Node.js program as a Windows service __js

Source: Internet
Author: User

Reprint Address: http://www.grati.org/?p=236

Write an article on the deployment of the Nodejs program in Windows and provide a "deploying-node-with-spark (how do I use Spark deployment node)" On the Lemonhall request. The link to the article (thank you very much lemonhall), today is free just to say.

Most of the applications written by Nodejs are network services, so it is very necessary to make them perform in a deamon manner. I have a two-point understanding of "Deamon": 1: Able to implement the power-on automatically, and no user login.  A valid user ID and group ID (which determines deamon permissions) for a 2:deamon program is generally not a common operating account for a computer. To enable an application to be executed Deamon in Windows, simply register it as a system service. Two gadgets are available in the WINDOWSNT Resource Kit Instrsrv.exe and Srvany.exe, according to Microsoft's official version of the two programs to support Winnt and Win2K, but after the results of the search on the Internet, they can also run on the XP (as for the WinServer2008 can not Can use, have the condition to help try it. The specific deployment of the method, I reprinted a Slyar article win under the system automatically run the program, no longer write again.

Finally, my point is that in Windows, Nodejs is run through the middle tier of the Cygwin, so performance and stability should not be comparable to the native programs of Unix-like platforms. Using Nodejs in Windows should be just for debugging purposes, in the production environment stable and performance first, convenient line can be slightly sacrificed a little. So in the production environment or deployment on the linuxserver better.

PPS: To say a little bit of my understanding of Nodejs programming Methods: Nodejs program does not use the debugger, habits vs friends may feel very awkward, in fact, the unit test refinement, each implementation of a function or even write a function can be tested to see if the function is expected to work in the way. Also, be sure to output the log clearly. In this way, the program can be written without the debugger, and the quality of the code can be improved, the final calculation, the development speed does not necessarily slow.

The following method of service registration:

Windows NT Resource Kit offers 2 gadgets to help me:

Instrsrv.exe installs and removes system services from Windows NT.

Srvany.exe allows any Windows NT application to run as a service.

Instsrv.exe can install and remove services to the system, Srvany.exe can allow programs to run in a service way. Below I say the concrete installation process.

1, put Instsrv.exe and Srvany.exe into a directory, the following with%path% instead of path

2, open cmd, enter the following content, which servername for you to create the service name

%path%\instsrv ServerName%path%\srvany.exe

3, open the Regedit Registry Editor, find the following directory

Hkey_local_machine\system\currentcontrolset\services\<servername>

4, right mouse click <servername>, create an "item", the name is "Parameters"

5, the left mouse button click "Parameters", right click on the right mouse button to create a "string value" (REG_SZ), named "Application", the numerical data fill in the full path of the program you want to execute.

6 (optional), the left mouse button click "Parameters", right click on the right mouse button, create a "string value" (REG_SZ), named "DependOnService", the value data in the service dependent service name. Don't know what dependencies are, you can keep going without knowing, I don't explain.

7, open the Services.msc Service Control Panel, find <servername>, right mouse button-Properties-login, check "Allow services and desktop interaction" (generally you want to run the program has an interface bar). Well, that's usually it.

The two gadgets mentioned in the article are downloaded.

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.