Install a Node.js Application as a Windows Service

Mark Barton
InstructorMark Barton
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 6 years ago

For a production Windows server it makes sense to run NodeJS applications as a Windows service. This way they can be automatically restarted if the server is rebooted.

It also makes it easier to use monitoring tools like datadog to detect if there are issues with the service which is critical for production systems.

Instructor: [00:00] One of the easiest ways to install a node application as a window service is to use an application called NSSM. NSSM stands for the Non-Sucking Service Manager, and you can download it from this URL.

[00:12] After installing NSSM, if you open a command prompt with administration access and navigate to the directory, entering NSSM on its own will give you a list of commands. What we want to use is NSSM install.

[00:28] We're also going to give it a name. I recommend you prefix all your services with a common set of initials, making them easier to find in the task manager. We'll call ours MBS. This will then display the NSSM GUI.

[00:41] Within the NSSM GUI, the first thing we want to do is find the path to our node.exe. This is what we're going to use to start our node service.

[00:56] The next thing we need is a startup directory. This is the directory that our app lives in. Finally, we need to give the arguments we would give to the command line. In our case, we would use start, as in node-start.

[01:13] The service name is what we gave it when we launched this GUI, and that's fine. The details, we will keep the display name the same. The description should be something meaningful who would understand what the service does.

[01:30] Startup type, will either be automatic, so when the service reboots the service restarts, which is what you would normally want.

[01:36] Automatic delayed start, that will be if you want the service to not start initially and give a chance for something else to start. Manual and disabled are if you don't want this to be an automatic starting service. Log on.

[01:50] This is a test box. We're going to use a local system account. In production, you should use a user account that has sufficient access to run the service.

[01:59] Dependencies, this allows you to define other services that this service may rely on. For instance, you may want to specify MongoDB starts first before this service starts. Let's install the service. We get a prompt back from NSSM saying successfully installed.

[02:15] Looking under our services within task manager, we see our new service mbtest, which is currently stopped. I open the services up, find the disservice, I can now start it. My service is now successfully started. If the server is restarted, this service will start automatically.

[02:34] One thing you need to do is you should be remotely monitoring your window services to make sure that this is running successfully.