NGROK 请求错误:连接 ECONNREFUSED 127.0.0.1:4040

问题描述 投票:0回答:1

我在设置ngrok隧道时偶尔会遇到以下错误。有什么想法可以解决吗?

RequestError: connect ECONNREFUSED 127.0.0.1:4040
    at ClientRequest.<anonymous> (C:\Users\user\Downloads\Node\RequestLogger_Dev\node_modules\got\dist\source\core\index.js:970:111)
    at Object.onceWrapper (node:events:629:26)
    at ClientRequest.emit (node:events:526:35)
    at origin.emit (C:\Users\user\Downloads\Node\RequestLogger_Dev\node_modules\@szmarczak\http-timer\dist\source\index.js:43:20)
    at Socket.socketErrorListener (node:_http_client:495:9)
    at Socket.emit (node:events:514:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16) {
  code: 'ECONNREFUSED',
  timings: {
    start: 1702548022231,
    socket: 1702548022232,
    lookup: undefined,
    connect: undefined,
    secureConnect: undefined,
    upload: undefined,
    response: undefined,
    end: undefined,
    error: 1702548022233,
    abort: undefined,
    phases: {
      wait: 1,
      dns: undefined,
      tcp: undefined,
      tls: undefined,
      request: undefined,
      firstByte: undefined,
      download: undefined,
      total: 2
    }
  }
}

NGROK Error

代码:

// Asynchronous function to set up an ngrok tunnel
async function setupNgrokTunnel() {
    try {
        // Connect to ngrok, providing the port, authentication token, and disabling TLS binding
        const url = await ngrok.connect({ addr: config.PORT, authtoken: config.AUTH_TOKEN, bind_tls: false });

        // Log the public URL of the ngrok tunnel
        console.log('\nNgrok Tunnel URL:', url);

        // Update the server's endpoint in the configuration with the ngrok tunnel URL
        config.ENDPOINT = url;

        // Close the ngrok tunnel when the application exits
        process.on('SIGINT', async () => {
            await ngrok.disconnect();
            console.log("close...........")
            process.exit();
        });
    } catch (err) {
        // Handle errors during ngrok tunnel setup and log the details
        console.error('\nError creating ngrok tunnel:', err);

        // Update the configuration with the error details
        config.ERROR = err;
    }
}

Code

node.js express ngrok tunnel
1个回答
0
投票

也许检查一下是否有任何进程已经在后台运行 ngrok。

© www.soinside.com 2019 - 2024. All rights reserved.