title: How Nginx handles outgoing requests going from nodejs as a client?
body: <p>Intro:
  I have and angular frontend and node backend (Server A) working fine. Using nginx as well for Server A.
  Now from my node server (Server A) I need to call an API endpoint of other server (Server B).</p>
  <p>Nginx configurations for Server B wont matter because curl command is working fine.</p>
  <p>I have a PUT and POST <code>https</code> outgoing request from my node server to other server. On my system I have nginx service working.</p>
  <p>The API is working fine when I use <code>curl</code> from the terminal but for the same thing via node <code>https</code> module the server is giving 400 BAD REQUEST.</p>
  <ol>
  <li>What is the process for outgoing requests for nginx?</li>
  <li>Why is the curl command working and node env requests not working?</li>
  </ol>
  <pre><code>curl -i --insecure --request PUT --url https://example.com:443/update --header 'content-type:application/json'  --data '{&quot;example&quot;:&quot;Goodmorning&quot;}'
  
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>httpsRequest(serverurl, method, header, data, callback){
      console.log(&quot;httpsRequest function body&quot;)
      let datastr = &quot;&quot;;
  
      if (data !== undefined)
          datastr = JSON.stringify(data);
      const options = {
         host:'example.com',
         port : 443,
         rejectUnauthorized: false,
         path : &quot;/update&quot;,
         body : datastr,
         method : method,
         secure:false,
         key : readFileSync(&quot;example.key&quot;),
         cert : readFileSync(&quot;example.crt&quot;),
        };
      if (header !== undefined) {
            options['headers'] = header
  };
      }
      console.log(&quot;options\n&quot;, options);
  
      process.env[&quot;NODE_TLS_REJECT_UNAUTHORIZED&quot;] = 0;
      options.agent = new https.Agent(options);
  
      // options.agent = httpsAgent;
      const req = https.request(options, (res) =&gt; {
          console.log('status code ', res.statusCode);
          console.log('headers:', res.headers);
  
          res.on('data', (d) =&gt; {
              process.stdout.write(d);
              console.log(d);
              if(res.statusCode === &quot;errorexample&quot;){
                  callback(null, {data : &quot;success&quot;})
              }else{
                 let errormsg = {
                      message : res.message,
                      statusCode : res.statusCode,
                      failureAlarmCode : res.failureAlarmCode
                  }
                  callback(null, { &quot;error&quot;: errormsg });
              }
            });
      });
  
      req.on('error', (e) =&gt; {
          console.error(e);
          callback(e, null);
        });
      req.end();
  
  }
  
  </code></pre>
  <p>I think the curl from terminal does not route via the client nginx, hence some difference there. AM I correct?</p>