Skip to content

Instantly share code, notes, and snippets.

@justinbalaguer
Last active August 7, 2020 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinbalaguer/6c447408909f29b9c92437dae428d656 to your computer and use it in GitHub Desktop.
Save justinbalaguer/6c447408909f29b9c92437dae428d656 to your computer and use it in GitHub Desktop.
Run a Node.js app as a windows service
// - on the root of the project directory create a `myservice.js`
// - code:
const Service = require('node-windows').Service;
// Create a new service object
const svc = new Service({
name:'My Service Name',
description: 'My service description',
script: 'C:\\Path\\to\\myservice.js',
nodeOptions: [
'--harmony',
'--max_old_space_size=4096'
]
//, workingDirectory: '...'
//, allowServiceLogon: true
});
// Listen for the "install" event, which indicates the
// process is available as a service.
svc.on('install',function(){
svc.start();
});
svc.install();
// - run `node myservice.js`
// - accept all pop-ups
// - windows+r: services.msc
// - check the name of the service if its there
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment