How to resolve hostname to an ip address in node js
<p>I need to resolve hostname defined in hosts file to its corresponding IP address.</p>

<p>For example my host file look like this - "/etc/hosts"</p>

<pre><code>127.0.0.1    ggns2dss81 localhost.localdomain localhost
::1     localhost6.localdomain6 localhost6
192.168.253.8    abcdserver
192.168.253.20   testwsserver
</code></pre>

<p>Now in my <code>node.js</code>, i can read content of this file, but i need to fetch for given <code>hostname</code>.</p>

<pre><code>hostname = "testwsserver"
hostIP = getIP(hostname);
console.log(hostIP); // This should print 192.168.253.20
</code></pre>

<p><strong>PS</strong> - <code>npm pkg</code> or any third party package cannot be installed on machine.</p>

<p>Help is much appreciated!!</p>