MVP, Author

Auto-Starting Node Server

Hits: 151

In this post we are going to create a windows service to keep the Node server keep alive all time. If the server is unavailable then the service will automatically start the server in background using command.

Learn how to create a new service by following the link:

Let’s create a new windows service for our Node server like below image.

App.Config: Change the app path and port in app.config file to run the application according to the app configuration.

Add “NLiveService.cs” file in your application, then modify the service with below code samples..

Timer Tick: Here’s is the timer deceleration for our service job. the interval time is 30 second.

Run Command: This is where we are running the command after checking the port is running or not.

Finally: This is the full service class.

Utility: This is where we are checking the port and writing the log.


I’ve uploaded the full source code to download/clone @github

MSI-Setup File

Step-1: Enter Details

Step-2: Choose File Type

Step-3: Choose project package path to save in local folder.

Step-4: Import Solution file from Service project folder.

Step-5: Choose Debug folder to import compiled components.

Step-6: Choose Service output file like below screen

Step-7: As this is a service so we are not creating any shortcut of service file.

Step-8: Skip this step as we don’t have any activity with this step.

Step-9: Choose a setup wizard theme.

Step-10: Choose your desired language, by default English is chosen.

Step-11: As this is an example with sample setup so we are skipping this step.

Step-12: Finally finish the configuration wizard.

Step-13: In this step we are going to add the service which will install with setup process.

Step-14: Choose output file to attach with installer.

Step-15: Click on the file then press Ok button.

Step-16: After choosing the file and finishing all those steps, lets build the project like below screen.

Step-17: Un-Check the option to not listed in control panel Add/Remove program.

Step-18: Finally Run the project.

Step-18: Continue the setup process by clicking Next. After successful installation the service will start automatically.

Step-19: Go to task manager to see the running process like below screen.

Now browse http://localhost:3000  in browser to see Node application is running. Go to “C:\Program Files (x86)\OnAir\NLiveService” folder open the log file to see the status of running port like below screen.


I’ve uploaded the full source code of setup file to download/clone @github, Thanks 🙂

Post a comment