diff --git a/lib/dns.js b/lib/dns.js index 8d1541718abf75..3fd5184d83f4ca 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -191,9 +191,12 @@ exports.lookupService = function(host, port, callback) { if (isIP(host) === 0) throw new TypeError('"host" argument needs to be a valid IP address'); - if (port == null || !isLegalPort(port)) + if (!isLegalPort(port)) throw new TypeError(`"port" should be >= 0 and < 65536, got "${port}"`); + if (typeof callback !== 'function') + throw new TypeError('"callback" argument must be a function'); + port = +port; callback = makeAsync(callback); diff --git a/test/parallel/test-dns.js b/test/parallel/test-dns.js index cd5914e026d6a9..6a73371b02f0c2 100644 --- a/test/parallel/test-dns.js +++ b/test/parallel/test-dns.js @@ -177,3 +177,7 @@ assert.throws(function() { assert.throws(function() { dns.lookupService('0.0.0.0', 'test', noop); }, /"port" should be >= 0 and < 65536, got "test"/); + +assert.throws(() => { + dns.lookupService('0.0.0.0', 80, null); +}, /^TypeError: "callback" argument must be a function$/);