How to resolve hostname to an ip address in node js

How about NodeJS documentation - DNS – have you checked it?

const dns = require('dns')

dns.lookup('testwsserver', function(err, result) {
  console.log(result)
})

Just to build on Krzysztof Safjanowski's answer,

you can also use the builtin promisify utility to convert it to a promise rather than a callback.

const util = require('util');
const dns = require('dns');
const lookup = util.promisify(dns.lookup);

try {
  result = await lookup('google.com')
  console.log(result)
} catch (error) {
  console.error(error)
}