问题描述
我试图在 NodeJs 服务器上的 app.get() 期间从 IBM Watson 获取信息。从 Watson 获取信息的代码有效,我正在努力将其发送回客户端。 但是每当我添加额外的 console.print( words ) 时,它都会吓坏并抱怨在我添加新的 console.print() 语句之前完全不同的行。
app.get("/text/emotion",(req,res) => {
const nlu = getNLUInstance();
//console.log( "request /text/emotion");
var parameters = { text: "I am having a bad day today,\
Could someone help me please",features : {emotion: {}}}
ret = nlu.analyze( parameters ) //,function( error,response){
.then (analysisResults => {
console.log(JSON.stringify(analysisResults,null,2));
console.log( "in here")
})
.catch(err=> {console.log( "error",err);
});
console.log( ret );
return res.send({"happy":"10","sad":"50"});
});
app.get("/text/sentiment",res) => {
return res.send("text sentiment for "+req.query.text);
});
let server = ***app.listen(8080,()*** => {
console.log('Listening',server.address().port);
});
这有效,但如果我在 console.log(ret) 上方添加另一个 console.log("Here") 语句,它会担心 app.listen(8080... 调用。错误指向 app.listen 之间的点“.”
所以代码不起作用
console.log( "here");
console.log( ret );
return res.send({"happy":"10","sad":"50"});
});
但是这段代码可以
console.log( ret );
return res.send({"happy":"10","sad":"50"});
});
[nodemon] starting `node sentimentAnalyzerServer.js`
events.js:292
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::8080
at Server.setupListenHandle [as _listen2] (net.js:1313:16)
at listenInCluster (net.js:1361:12)
at Server.listen (net.js:1447:7)
at Function.listen (/home/project/cazgi-IBM-Watson-NLU-Project-1/sentimentAnalyzeServer/node_modules/express/lib/application.js:618:24)
at Object.<anonymous> (/home/project/cazgi-IBM-Watson-NLU-Project-
1/sentimentAnalyzeServer**/sentimentAnalyzerServer.js:64:18)**
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
Emitted 'error' event on Server instance at:
at emitErrorNT (net.js:1340:8)
at processticksAndRejections (internal/process/task_queues.js:84:21) {
code: 'EADDRINUSE',errno: 'EADDRINUSE',syscall: 'listen',address: '::',port: 8080
}
[nodemon] app crashed - waiting for file changes before starting...
看来,不管我把额外的console.log 语句,它只是不喜欢它们。 或者有没有更好的方法来调试这些东西。我正在使用终端来完成所有这些。 我对 Node.js 和 javascript 很陌生,但这对我来说似乎不合适。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)