简体   繁体   English

当似乎没有其他应用程序正在尝试使用端口时,如何修复Node.js中的“ events.js:167错误错误:连接ECONNREFUSED 127.0.0.1:443”?

[英]How to fix 'events.js :167 error Error: connect ECONNREFUSED 127.0.0.1:443' in Node.js when no other apps seems to be attempting to use the port?

I'm getting the error described below when running my node.js app after perfoming a few api calls. 在执行了一些api调用后,运行node.js应用程序时出现以下错误。

The error does not always show in the exactly same place/line of code. 该错误并不总是显示在完全相同的代码位置/行中。 But most of the times it is at the end of the api call. 但大多数情况下,它是在api调用的结尾。

  events.js:167 

throw er; 投掷者 // Unhandled 'error' event ^ //未处理的“错误”事件^

Error: connect ECONNREFUSED 127.0.0.1:443 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1113:14) Emitted 'error' event at: at TLSSocket.socketErrorListener (_http_client.js:391:9) at TLSSocket.emit (events.js:182:13) at emitErrorNT (internal/streams/destroy.js:82:8) at emitErrorAndCloseNT (internal/streams/destroy.js:50:3) at process._tickCallback (internal/process/next_tick.js:63:19) 错误:在TCPConnectWrap.afterConnect上将ECONNREFUSED 127.0.0.1:443连接为[oncomplete](net.js:1113:14)在TLSSocket.emit的TLSSocket.socketErrorListener(_http_client.js:391:9)处发出了“错误”事件(events.js:182:13)在process._tickCallback(内部/ process / next_tick)处在emissionErrorAndCloseNT(内部/流/destroy.js:50:3)在emitErrorNT(内部/流/destroy.js:82:8)处。 JS:63:19)

Based on similar questions here at SO my hypothesis is that a) there is something using 127.0.0.1:443 and therefore conflicting with my app or b) node is trying to use 127.0.0.1:443 but there is nothing there for it to use (my app is listening to localhost :3000). 基于此处类似的问题,我的假设是:a)使用127.0.0.1:443的某个东西,因此与我的应用程序发生冲突;或b)节点正尝试使用127.0.0.1:443,但没有任何可使用的东西(我的应用正在监听localhost:3000)。

Hyphothesis a) doesn't seem likely since after running netstat -ano | 假设a)似乎不太可能,因为运行netstat -ano之后| findstr 127.0.0.1:443 nothing shows up (when app is running and right after it terminates). findstr 127.0.0.1:443没有任何显示(当应用程序运行时以及终止后)。

Also killed every node.exe and mongod.exeb using any port in my computer, closed the terminal and restarted the node app without success. 还使用计算机中的任何端口杀死了每个node.exe和mongod.exeb,关闭了终端并重新启动了节点应用程序,但均未成功。

In case error is related with hypothesis b) I'm not sure how to address it. 如果错误与假设有关b)我不确定该如何解决。

api.post('/parsePOpdf', wagner.invoke(function(Pdfeq, Pdfdocspec, Product, User, Order){
    return async function(req,res){

        //... some code

        pdfParser.on("pdfParser_dataError", errData => console.error(errData.parserError) );
        pdfParser.on("pdfParser_dataReady", async function(pdfData) {

            fs.writeFile("./test.json", JSON.stringify(pdfData), function(err){
                console.log(err);
            });

            let pages = pdfData.formImage.Pages;
            //console.log('pages 557', pages);
            let order = {
                orderDetails : {
                    supplier : [{
                        item : []
                    }]
                }
            }; 

            for (const page of pages){
                let value = await getItemsInPDF(page, productKeys, pdfParsingDetails, order, Product, customer, supplierLink, User);
                //... more code
                order = value;
            }

            return res.json(order);         
        });
        pdfParser.loadPDF(pdfFile);

    }   
}));

I would expect the code to finish without throwing this error. 我希望代码能够完成而不会引发此错误。

It turns out that the problem was in the api code: an http.get line to fetch a remote file was generating the conflict. 事实证明,问题出在api代码中:用于获取远程文件的http.get行生成了冲突。 This makes sense since the error was not present for other endpoints of the api. 这是有道理的,因为该API的其他端点不存在该错误。

So learning is that if the terminal reports no app using the suspected conflicting port (see question) answser should be within the same code and you need to go line by line to identify which one is causing the problem (instead of focusing on other apps trying to use the same port, like I was focusing on). 因此,需要了解的是,如果终端报告没有使用可疑冲突端口(请参阅问题)的应用,则answser应该在同一代码内,并且您需要一行一行地找出导致问题的原因(而不是专注于尝试其他应用)使用同一端口,就像我一直关注的那样)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM