MCPcopy Index your code
hub / github.com/nodejs/node / lookup

Function lookup

lib/internal/dns/promises.js:196–239  ·  view source on GitHub ↗

* Get the IP address for a given hostname. * @param {string} hostname - The hostname to resolve (ex. 'nodejs.org'). * @param {object} [options] - Optional settings. * @param {boolean} [options.all] - Whether to return all or just the first resolved address. * @param {0 | 4 | 6} [options.family]

(hostname, options)

Source from the content-addressed store, hash-verified

194 * @returns {Promise<object>}
195 */
196function lookup(hostname, options) {
197 let hints = 0;
198 let family = 0;
199 let all = false;
200 let dnsOrder = getDefaultResultOrder();
201
202 // Parse arguments
203 if (hostname) {
204 validateStringWithoutNullBytes(hostname, 'hostname');
205 }
206
207 if (typeof options === 'number') {
208 validateOneOf(options, 'family', validFamilies);
209 // Coerce -0 to +0.
210 family = options + 0;
211 } else if (options !== undefined && typeof options !== 'object') {
212 throw new ERR_INVALID_ARG_TYPE('options', ['integer', 'object'], options);
213 } else {
214 if (options?.hints != null) {
215 validateNumber(options.hints, 'options.hints');
216 hints = options.hints >>> 0;
217 validateHints(hints);
218 }
219 if (options?.family != null) {
220 validateOneOf(options.family, 'options.family', validFamilies);
221 // Coerce -0 to +0.
222 family = options.family + 0;
223 }
224 if (options?.all != null) {
225 validateBoolean(options.all, 'options.all');
226 all = options.all;
227 }
228 if (options?.verbatim != null) {
229 validateBoolean(options.verbatim, 'options.verbatim');
230 dnsOrder = options.verbatim ? 'verbatim' : 'ipv4first';
231 }
232 if (options?.order != null) {
233 validateOneOf(options.order, 'options.order', validDnsOrders);
234 dnsOrder = options.order;
235 }
236 }
237
238 return createLookupPromise(family, hostname, all, hints, dnsOrder);
239}
240
241
242function onlookupservice(err, hostname, service) {

Callers 2

lookup4Function · 0.50
lookup6Function · 0.50

Calls 3

getDefaultResultOrderFunction · 0.85
validateHintsFunction · 0.85
createLookupPromiseFunction · 0.85

Tested by

no test coverage detected