1

Is there a way to have the express.js server always use do a dns look up for IPV4 addresses instead of both IPv4 and IPV6 addresses?

Like we do this in a java JVM by setting the parameter java.net.preferIPv4Stack=true

I am looking to do this for outgoing requests, when my add is making outbound service calls. My app uses request npm package and it uses net npm package and it uses dns npm package. The dns package has an option to set the IP family which can be 4 or 6. I think this will do what i want if i set it to 4.

Now the question is, how to pass this option from my app to be applied to this npm package at runtime.

mandy
  • 735
  • 1
  • 9
  • 24
  • you can specify IPv4 when you specify for server to listen on port `XXXX` just like this `app.listen(5000, '127.0.0.1');` – Satish Patel Sep 05 '17 at 14:43
  • @SatishPatel, thanks for the response. I have updated my question above. Apologies for lack of clarity. – mandy Sep 05 '17 at 15:29

1 Answers1

1

I had to do this to force the DNS look up to be looking up only IPv4 addresses and not IPv6 addresses.

import Request from 'request';

export class SoapUtility extends Utility 
{

  constructor(options) {
        super();
        otherCode = otherCode;

        this.request = Request;
  };

  requestMainframe(args, callback) 
  {
    this.request.post({
        url: this.endpoints.userLookup,
        method: 'POST',
        family : 4,
        headers: {
            'Content-Type': 'text/xml',
            "Authorization": `Basic ${creds}`
        },
        body: requestBody,
        rejectUnauthorized: false, 
    }, (error, response, body) => {
          callback(error, null);
    });
  }
}

Here is the documentation from npm request and DNS lookup details

mandy
  • 735
  • 1
  • 9
  • 24