Search code examples
node.jsexpressdebuggingfiddler

How to correctly trace all outboud Node.js request on server apps with Express


I try many library, last library I try was global-tunnel-ng, but still have no result. Usually I use fiddler to trace various request, my Fiddler listen port 8888, therefore I try to use

  var globalTunnel = require('global-tunnel-ng');
  globalTunnel.initialize({
    host: 'ipv4.fiddler',
    port: 8888,
  });

  // my various request to Google, to AWS and more

  globalTunnel.end()

I expected to see all request on Fiddler, but there are nothing any request on Fiddler panel. 'localhost' and '127.0.0.1' as ProxyURL also don't working. What I doing wrong?


Solution

  • Node.js ignores proxy settings by default, unlike many languages (see https://github.com/nodejs/node/issues/8381) so it can be challenging to capture this traffic.

    There are various libraries that can do this for some cases (global-agent covers most recent APIs - but not all of them, e.g. it won't capture requests via Undici & Node's fetch global).

    In future, this may be slowly resolved by https://github.com/nodejs/undici/issues/1650 and other similar efforts, but I suspect that won't be universal any time soon.

    I also ran into this, and Fiddler and other alternatives are not very helpful here, so I built my own open-source HTTP debugging alternative app which can handle Node.js interception automatically. Take a look at https://httptoolkit.com/javascript/ for more info. If you use this instead of Fiddler, you can open a terminal in one click, and then outgoing traffic from any Node process started in that terminal will be intercepted automatically, for all cases I'm aware of (http and https modules, fetch, Unidici, etc).