微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

当我在 apt.get()

如何解决当我在 apt.get()

我试图在 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"});
});

这是添加额外的console.log()时的错误输出

[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 举报,一经查实,本站将立刻删除。