How can I get the FQDN (Fully Qualified Domain Name) of the machine on which node is running?
os.gethostname()
is not sufficient, since it usually returns the unqualified DN, only. Same thing for dns.reverse(ip, callback)
- assuming the ip is the one associated with the hostname, e.g. obtained using dns.lookup(os.gethostname()[, options], callback)
.
Also doing a shell.exec("hostname -f", { silent: true }, cb)
is not an option, since it is not POSIX compliant and thus will fail e.g. on Solaris et. al., and it is a really bad hack, since exec() is a very, very expensive call wrt. resources like RAM and CPU (causes context switching).
$(hostname).$(domainname)
will work on both Solaris and Linux. But, not only is Solaris POSIX, it's POSIX-certified! It's more POSIX than Linux is. – Will Feb 03 '16 at 21:54