Node-windows Library

Using node-windows (JavaScript approach)

Step 1: Install node-windows

Inside your project:

npm install -g node-windows

Or locally:

npm install node-windows

Step 2: Create a Service Script (e.g., service.js)

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

// Create a new service object
const svc = new Service({
  name: 'My Node App',
  description: 'Node.js App running as a service',
  script: 'C:\\myapp\\app.js',
  nodeOptions: [
    '--harmony',
    '--max_old_space_size=4096'
  ]
});

// Listen for the "install" event
svc.on('install', () => {
  console.log('Service installed');
  svc.start();
});

svc.install();

Step 3: Run the Script to Install the Service

node service.js

Step 4: Check Services

You can now manage the service from:

  • services.msc

  • net start "My Node App" / net stop "My Node App"

Last updated

Was this helpful?