title: How can I send request via proxy server in nodejs?
body: <p>In java, I can send request via proxy server as</p>
  <pre class="lang-java prettyprint-override"><code>HttpClient clinet = HttpClient.newBuilder()
          .proxy(ProxySelector.of(new InetSocketAddress(&quot;proxy.server&quot;, portNum)))
          .build();
  HttpRequest request = HttpRequest.newBuilder()
          .uri(URI.create(&quot;https://server.I.want.to.send.request&quot;))
          .POST(HttpRequest.BodyPublishers.noBody())
          .build();
  
  HttpResponse&lt;String&gt; response =  clinet.send(request, HttpResponse.BodyHandlers.ofString());
  System.out.println(response.statusCode());
  System.out.println(response.body());   
  </code></pre>
  <p>I have tested with code above and checked it works just fine.</p>
  <p>But if I want to do the same thing in nodejs (react) it seems like it doesn't work.</p>
  <pre class="lang-js prettyprint-override"><code>const agent = httpsProxyAgent('proxy.server:portNum');
  
  axios.request({
      method: 'POST',
      url: &quot;https://server.I.want.to.send.request&quot;,
      data: {body},
      httpsAgent: agent
  });
  </code></pre>
  <p>As far as I understand, code above is the best I can try with JavaScript in react.<br />
  I have tried it, but it fails with timeout error (which means request doesn't go through proxy server I guess)</p>
  <p>Could anyone can give me an advise to solve this problem?</p>