Node.js http client with custom lookup logic

A lot of interesting things have happened with the convergence of io.js and Node.js. The latest Node.js (v4.2.1 at the time of writing) is based on io.js v3.x. In the io.js v2.0.0 release, I added the ability to specify a custom lookup function to net.createConnection. It allows one to do fun things like cache a dns lookup or add certain tracing logic into lookups. This is a quite specific use case, but can really improve performance in a lot of cases. Below is an example of implementing a custom lookup in Node’s http client. This is done merely to show the new capabilities, but I would not recommend using this particular solution in a production environment without understanding the implications.

Disclaimer: DNS records can change and this example does not take that into account.

Like what you read? Give Evan Lucas a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.