经常会遇到需要系统重启后自动执行的一些任务,在windows 上可以将对应的程序打包成service 然后自启动即可。
npm install node-windows -g
var Service = require('node-windows').Service;
// Create a new service object
var svc = new Service({
name:'Anywhere-auth module by nodejs',
description: 'The nodejs.org example web server.',
script: 'd:\\abc\\win\\app.js',
nodeOptions: [
'--harmony',
'--max_old_space_size=4096'
]
});
// Listen for the "install" event, which indicates the
// process is available as a service.
svc.on('install',function(){
svc.start();
});
svc.install();
var exec = require('child_process').exec;
exec('anywhere-auth -d d:/abc/ -s -p 999',function(){});
node index.js //执行打包代码,然后一路提示通过即可。
转载请注明出处: https://chrunlee.cn/article/package-nodejs-to-windows-service.html