我正在尝试编写一个在端口上侦听并写入事件日志的节点服务,但是当我在http://localhost:41414/?x=y
启动浏览器时无法连接,我没有从侦听器文件中获取事件记录(启动快递服务器)。知道我在做什么错吗?
我使用节点窗口创建了服务:使用(node mysvc.js --install 42424
)
var Service = require('node-windows').Service;
//-----------------------------------------------init vars
// Create a new service object
var svc = new Service({
name:'My Listener v1.1',
script: require('path').join(__dirname,'listener.js '+port)
});
// Listen for the "install" event, which indicates the
// process is available as a service.
svc.on('install',function(){
svc.start();
});
// Listen for the "uninstall" event so we know when it's done.
svc.on('uninstall',function(){
console.log('Uninstall complete.');
console.log('The service exists: ',svc.exists);
});
//-------------------------------------------------------end init vars
var port=0;
if(process.argv[2]=="--uninstall")
svc.uninstall();
else if(process.argv[2]=="--install")
if(parseInt(process.argv[3])>0){
port=parseInt(process.argv[3])
svc.install();
}
else{
console.log('must pass --install or --uninstall flag')
return;
}
listener.js开始在端口上侦听:
const express = require('express');
var EventLogger = require('node-windows').EventLogger;
var log = new EventLogger('My Listener');
port=41414
app.get('/data', (req, res) => {
const jdata = req.params[0];
log.info(jdata+' WOOOOO!!!!');
})
log.log(`Service listening on port ${port}`);
app.listen(port);
答案 0 :(得分:1)
您只是在listener.js中错过了这一行
const app = express()