Run Pareto Anywhere as a Windows service

Our step-by-step guide for production deployments on Windows machines

Run Pareto Anywhere as a Windows service

The TL;DR (Too Long; Didn't Read)

Learn how we at reelyActive use node-windows to run Pareto Anywhere in production on Windows machines.


Windows service?
A Windows service is simply a computer program that operates in the background on a Windows machine.
What's node-windows?
An open source library to install/start/stop/uninstall Node.js scripts as Windows background services for production environments.
Any Node.js program?
Yes, although this tutorial is specific to Pareto Anywhere, the concepts apply equally well to any Node.js program.

Create app.js   Step 1 of 3

Create the app.js file that defines how Pareto Anywhere will run as a Windows service.


Why app.js?
The node-windows library used to create the Windows service expects a file called app.js.
What does app.js do?
The file instructs the node-windows library how to create the Windows service, and how to handle service-specific events.
Create app.js for node-windows

Create app.js for Pareto Anywhere Part 1

In the root of the pareto-anywhere folder, create a file called app.js, copy Ctrl+C and paste Ctrl+V in the following contents:

const Service = require('node-windows').Service;

// Create a new service object
let svc = new Service({
    name: "Pareto Anywhere",
    description: "The open source IoT middleware by reelyActive",
    script: require('path').join(__dirname, 'bin//pareto-anywhere'),
    nodeOptions: [
      '--harmony',
      '--max_old_space_size=4096'
    ],
    workingDirectory: require('path').join(__dirname)
});

// The "install" event indicates that the process is available as a service.
svc.on('install', () => { svc.start(); });

// The "start" event indicates that process has actually started working.
svc.on('start', () => {
  console.log('Pareto Anywhere is running as a Windows Service.');
});

svc.install();

Customise app.js [OPTIONAL] Part 2

Edit the app.js file as required for the target environment.

For instance, to start Pareto Anywhere with a different script than the default, edit the bin//pareto-anywhere path of the script property (ex: bin//pareto-anywhere-influxdb2).

Install and link node-windows   Step 2 of 3

Install node-windows using npm and link from Pareto Anywhere.


Why node-windows?
/node-windows is an established open source library that does exactly what's required: simplifying the process of running a Node.js program as a Windows service.
Is Visual Studio required?
No! The node-windows library does not use native modules, and hence should install easily without cumbersome Windows dependencies, like Visual Studio.
Install and link node-windows

Install node-windows Part 1

From a terminal on the Windows machine, install the node-windows package globally with the command npm install -g node-windows.

Link Pareto Anywhere Part 2

From a terminal on the Windows machine, browse to the pareto-anywhere folder and create a symlink to the installed node-windows package with the command npm link node-windows.

Run and verify the Windows service   Step 3 of 3

Confirm that Pareto Anywhere is running consistently as a Windows service.


How does that work?
Simply running the app.js script will initiate the creation of a Windows service by the node-windows library.
Will it run on boot?
Yes, and that will be tested in Part 2 below.
Pareto Anywhere running as a Windows Service

Run as a Windows Service Part 1

From a terminal on the Windows machine, browse to the pareto-anywhere folder and run the app.js script with the command node app.js.

Open the Services app on the Windows machine and confirm that Pareto Anywhere is indeed running.

Open a web browser on the Windows machine and browse to http://localhost:3001 to observe the Pareto Anywhere home page.

Reboot and test Part 2

Reboot the Windows machine and confirm, as above, that Pareto Anywhere continues to run as a Windows service.


Where to next?

Continue exploring our open architecture and all its applications.