Links

NodeJS

1. Problems

  • Traffic from NodeJS doesn't show on the Proxyman app
  • Get SSL Error (unable to verify the first certificate)

2. Solution

By default, all HTTP/HTTPS Request from NodeJS doesn't go through HTTP Proxy Server. Thus, Proxyman could not capture the traffic.
Please follow the below steps to fix it:
  1. 1.
    Install global-agent package
npm install global-agent
2. At the top of your NodeJS code, add the following code:
import { bootstrap } from 'global-agent';
bootstrap();
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
3. Add this env to your current bash. Make sure Proxyman is listening at port 9090
export GLOBAL_AGENT_HTTP_PROXY=http://127.0.0.1:9090
4. Done ✅
Run your NodeJS Script again and the HTTP/HTTPS request would appear on the Proxyman app.

3. Sample code

import fetch from 'node-fetch';
// Setup global-agent
import { bootstrap } from 'global-agent';
bootstrap();
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
// fetch the data
const response = await fetch('https://httpbin.org/get?id=123');
const data = await response.json();
// Done
console.log(data);

4. Discussion