我正在尝试编写一个节点服务来侦听端口并写入事件日志,但是当我在http://localhost:41414/?x=y
我没有从侦听器文件(启动快速服务器)中获取事件记录时启动浏览器时无法连接。知道我做错了什么吗?
我使用 node-windows 创建了一个服务:使用 ( 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);