Capture NodeJS Traffic with Charles Proxy
Inspecting traffic is very valuable for debugging and troubleshooting.
Let’s assume that your application calls to myapi.com
and receives unexpected data. Want to view actual request and/or response headers and body? Charles proxy can receive traffic from the application and send it to the target server: myapi.com
while capturing all information.
Quick and simple approach described below will let capture your NodeJS application traffic: both HTTP and SSL / HTTPS. No additional dependencies required: only Charles proxy.
Configuring Charles:
- Go to Proxy » Reverse Proxies…
- Check Enable Reverse Proxies, add a target server:
Local Port: 60103
- any unused local port
Remote Host: myapi.com
- target host address
Remote Port: 443
- target host port
- For SSL / HTTPS traffic:
- Go to Proxy » SSL Proxying Settings… » SSL Proxying tab
- Check Enable SSL Proxying, add a target server:
Host: myapi.com
Port: 443
Configuring NodeJS application:
- Change requests options to point to Charles proxy instead of
myapi.com
:
host: localhost
port: 60103
- local port from reverse proxy settings - Charles uses self-generated SSL certificates, so to prevent certificate errors add following line:
Done! Enjoy debugging.
You could apply the rules only for debugging or development environment, for example with environment variable.
Charles proxy version used: v 3.10.1. It was tested on Mac OS and should work on Linux and Windows as well. You could also use free Fiddler proxy on PC.
comments powered by Disqus