Node.js an asynchronous event-driven JavaScript runtime. Node.js is designed to build scalable network applications. Node.js applications can be run as a Windows Service using FireDaemon Pro. This provides many benefits including allowing your Node.js application to start automatically at boot and run multiple simultaneous Node.js applications. 

How to Setup a Node.js Application Under FireDaemon Pro

Download and Install Node.js

Node.js can be downloaded and installed from here. Download the 64-bit version of Node.js. By default, Node.js installs into C:\Program Files\nodejs.

Download and Install FireDaemon Pro

FireDaemon Pro can be downloaded from here. By default, FireDaemon Pro installs into C:\Program Files\FireDaemon Pro.

Create your Node.js Application

For the purposes of this example, we created a simple webserver in Node.js. The script is placed in C:\Scripts. The scripts is called webserver.js. The code is as follows:

var http = require('http');

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Node.js application running under FireDaemon Pro control!');

Setup Your FireDaemon Pro Node.js Service

Start the FireDaemon Pro GUI and click the "+" button to create a new service definition. Enter the information as per the screenshot below adjusting your paths to suit.

Node.js applications are generally run in a terminal window on Session 0. To ensure they are shutdown gracefully, check the Console Program checkbox in the Lifecycle tab. The Shutdown By option will change to Ctrl+C.

Node.js FireDaemon Pro Lifecycle Configuration

If you need to debug your Node.js application you can create a FireDaemon Pro debug log as well as capturing the output of your Node.js script via Output Capture in the Logging tab per the screenshot below. We have used FireDaemon Pro environment variables to name the log files. This will name the log files "Node.JS Web Server Debug.log" and "Node.JS Web Server Stdout.log" respectively. The Debug Log File and Capture Stdout in File can be any legal Windows path and file name. Also check out FireDaemon Pro log rolling.

FireDaemon Pro Node.js Debug Logging Configuration

Now click on the "tick" in the toolbar to install the service. You will see the service running in the FireDaemon Pro GUI per the screenshot below (n.b. if you right click on the service, you will bring up the context menu where you can display the FireDaemon Pro Resource Monitor for the Node.js service).

Node.js FireDaemon Pro Service and Resource Monitor

Lastly, test your Node.js application. In this case point your web browser at http://localhost:8080.

Microsoft Edge showing Node.js application running under FireDaemon Pro control