title: How to debug Ngrok not starting via node module?
body: <p>I'm developing an app that uses Ngrok for dev. Running ngrok from console works:</p>
  <pre><code>ngrok http 3011
  </code></pre>
  <p>shows the &quot;console UI&quot; indicating that the tunnel is up and giving me the url to use.</p>
  <p>Now I'm trying to setup things so that developers don't need to copy-paste urls etc. But the very basic usage fails for me:</p>
  <pre><code>// prepare-server.ts
  
  import ngrok from 'ngrok'
  import config from '../config'
  
  (async () =&gt; {
      try{
          const nwhUrl = await ngrok.connect({ addr: config.serverPort })
          console.log(nwhUrl)
      } catch(e) {
          console.error('problem with ngrok:', e)
      }
  })()
  </code></pre>
  <p>Gives me (when run as <code>ts-node src/prepare-server.ts</code>):</p>
  <pre><code>problem with ngrok: NgrokClientError: 
      at NgrokClient.request (&lt;path to project&gt;\node_modules\ngrok\src\client.js:39:23)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)  
      at connectRetry (&lt;path to project&gt;\node_modules\ngrok\index.js:29:22) {
    response: &lt;ref *1&gt; IncomingMessage {
      _readableState: ReadableState {
        objectMode: false,
        highWaterMark: 16384,
        buffer: BufferList { head: null, tail: null, length: 0 },
        length: 0,
        pipes: [],
        flowing: false,
        ended: true,
        endEmitted: true,
        reading: false,
        sync: false,
        needReadable: false,
        emittedReadable: false,
        readableListening: true,
        resumeScheduled: false,
        errorEmitted: false,
        emitClose: true,
        autoDestroy: false,
        destroyed: false,
        errored: false,
        closed: false,
        closeEmitted: false,
        defaultEncoding: 'utf8',
        awaitDrainWriters: null,
        multiAwaitDrain: false,
        readingMore: false,
        decoder: [StringDecoder],
        encoding: 'utf8',
        [Symbol(kPaused)]: null
      },
      _events: [Object: null prototype] {
        end: [Array],
        aborted: [Array],
        error: [Array],
        readable: [Array],
        finish: [Function: onfinish],
        close: [Function: onclose]
      },
      _eventsCount: 6,
      _maxListeners: undefined,
      socket: Socket {
        connecting: false,
        _hadError: false,
        _parent: null,
        _host: null,
        _readableState: [ReadableState],
        _events: [Object: null prototype],
        _eventsCount: 7,
        _maxListeners: undefined,
        _writableState: [WritableState],
        allowHalfOpen: false,
        _sockname: null,
        _pendingData: null,
        _pendingEncoding: '',
        server: null,
        _server: null,
        parser: null,
        _httpMessage: [ClientRequest],
        _peername: [Object],
        [Symbol(asyncId)]: 15,
        [Symbol(kHandle)]: [TCP],
        [Symbol(kSetNoDelay)]: false,
        [Symbol(lastWriteQueueSize)]: 0,
        [Symbol(timeout)]: null,
        [Symbol(kBuffer)]: null,
        [Symbol(kBufferCb)]: null,
        [Symbol(kBufferGen)]: null,
        [Symbol(kCapture)]: false,
        [Symbol(kBytesRead)]: 0,
        [Symbol(kBytesWritten)]: 0
      },
      httpVersionMajor: 1,
      httpVersionMinor: 1,
      httpVersion: '1.1',
      complete: true,
      headers: {
        'content-type': 'application/json',
        date: 'Wed, 21 Jul 2021 10:14:40 GMT',
        'content-length': '168',
        connection: 'close'
      },
      rawHeaders: [
        'Content-Type',
        'application/json',
        'Date',
        'Wed, 21 Jul 2021 10:14:40 GMT',
        'Content-Length',
        '168',
        'Connection',
        'close'
      ],
      trailers: {},
      rawTrailers: [],
      aborted: false,
      upgrade: false,
      url: 'http://127.0.0.1:4041/api/tunnels',
      method: null,
      statusCode: 503,
      statusMessage: 'Service Unavailable',
      client: Socket {
        connecting: false,
        _hadError: false,
        _parent: null,
        _host: null,
        _readableState: [ReadableState],
        _events: [Object: null prototype],
        _eventsCount: 7,
        _maxListeners: undefined,
        _writableState: [WritableState],
        allowHalfOpen: false,
        _sockname: null,
        _pendingData: null,
        _pendingEncoding: '',
        server: null,
        _server: null,
        parser: null,
        _httpMessage: [ClientRequest],
        _peername: [Object],
        [Symbol(asyncId)]: 15,
        [Symbol(kHandle)]: [TCP],
        [Symbol(kSetNoDelay)]: false,
        [Symbol(lastWriteQueueSize)]: 0,
        [Symbol(timeout)]: null,
        [Symbol(kBuffer)]: null,
        [Symbol(kBufferCb)]: null,
        [Symbol(kBufferGen)]: null,
        [Symbol(kCapture)]: false,
        [Symbol(kBytesRead)]: 0,
        [Symbol(kBytesWritten)]: 0
      },
      _consuming: true,
      _dumped: false,
      req: ClientRequest {
        _events: [Object: null prototype],
        _eventsCount: 10,
        _maxListeners: undefined,
        outputData: [],
        outputSize: 0,
        writable: true,
        destroyed: false,
        _last: true,
        chunkedEncoding: false,
        shouldKeepAlive: false,
        useChunkedEncodingByDefault: true,
        sendDate: false,
        _removedConnection: false,
        _removedContLen: false,
        _removedTE: false,
        _contentLength: null,
        _hasBody: true,
        _trailer: '',
        finished: true,
        _headerSent: true,
        socket: [Socket],
        _header: 'POST /api/tunnels HTTP/1.1\r\n' +
          'user-agent: got (https://github.com/sindresorhus/got)\r\n' +    
          'content-type: application/json\r\n' +
          'accept: application/json\r\n' +
          'content-length: 74\r\n' +
          'accept-encoding: gzip, deflate, br\r\n' +
          'Host: 127.0.0.1:4041\r\n' +
          'Connection: close\r\n' +
          '\r\n',
        _onPendingData: [Function: noopPendingOutput],
        agent: [Agent],
        socketPath: undefined,
        method: 'POST',
        maxHeaderSize: undefined,
        insecureHTTPParser: undefined,
        path: '/api/tunnels',
        _ended: true,
        res: [Circular *1],
        aborted: false,
        timeoutCb: null,
        upgradeOrConnect: false,
        parser: null,
        maxHeadersCount: null,
        reusedSocket: false,
        timings: [Object],
        emit: [Function (anonymous)],
        [Symbol(kCapture)]: false,
        [Symbol(kNeedDrain)]: false,
        [Symbol(corked)]: 0,
        [Symbol(kOutHeaders)]: [Object: null prototype],
        [Symbol(reentry)]: true
      },
      timings: {
        start: 1626862480674,
        socket: 1626862480676,
        lookup: 1626862480677,
        connect: 1626862480677,
        secureConnect: undefined,
        upload: 1626862480677,
        response: 1626862480678,
        end: 1626862480680,
        error: undefined,
        abort: undefined,
        phases: [Object]
      },
      emit: [Function (anonymous)],
      requestUrl: 'http://127.0.0.1:4041/api/tunnels',
      redirectUrls: [],
      request: Request {
        _readableState: [ReadableState],
        _events: [Object: null prototype],
        _eventsCount: 16,
        _maxListeners: undefined,
        _writableState: [WritableState],
        allowHalfOpen: true,
        requestInitialized: true,
        redirects: [],
        retryCount: 0,
        _progressCallbacks: [],
        write: [Function: onLockedWrite],
        end: [Function: onLockedWrite],
        options: [Object],
        requestUrl: 'http://127.0.0.1:4041/api/tunnels',
        _cannotHaveBody: false,
        _noPipe: true,
        [Symbol(kCapture)]: false,
        [Symbol(downloadedSize)]: 168,
        [Symbol(uploadedSize)]: 74,
        [Symbol(serverResponsesPiped)]: Set(0) {},
        [Symbol(stopReading)]: true,
        [Symbol(triggerRead)]: false,
        [Symbol(jobs)]: [],
        [Symbol(body)]: '{&quot;addr&quot;:3011,&quot;proto&quot;:&quot;http&quot;,&quot;name&quot;:&quot;2fbfea07-1dc3-4d7b-acfc-20a68b755c10&quot;}',
        [Symbol(bodySize)]: 74,
        [Symbol(cancelTimeouts)]: [Function: cancelTimeouts],
        [Symbol(unproxyEvents)]: [Function (anonymous)],
        [Symbol(request)]: [ClientRequest],
        [Symbol(originalResponse)]: [Circular *1],
        [Symbol(isFromCache)]: false,
        [Symbol(responseSize)]: 168,
        [Symbol(response)]: [Circular *1],
        [Symbol(startedReading)]: true
      },
      isFromCache: false,
      ip: '127.0.0.1',
      retryCount: 0,
      rawBody: &lt;Buffer &gt;,
      body: '',
      [Symbol(kCapture)]: false
    },
    body: ''
  }
  </code></pre>
  <p>Note the 503 Service Unavailable code. How so if the CLI version works?</p>
  <p>Any ideas how to debug this? I've also tried this without options (<code>await ngrok.connect()</code>) and the output doesn't change much. And this is an absolutely basic example (see <a href="https://www.npmjs.com/package/ngrok#local-install" rel="nofollow noreferrer">docs</a>), so I can't really do more to simplify the code, looks like something about Ngrok internals... Node package is v4.0.1</p>
  <p>PS <a href="https://github.com/bubenshchykov/ngrok/issues/222" rel="nofollow noreferrer">this issue</a> is probably related or the same. While my problem takes place for Node 14.1.0, it's doesn't take place for Node 15.14.0.</p>