Last active
August 7, 2020 02:45
-
-
Save justinbalaguer/6c447408909f29b9c92437dae428d656 to your computer and use it in GitHub Desktop.
Run a Node.js app as a windows service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// - 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