* 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)
| 194 | * @returns {Promise<object>} |
| 195 | */ |
| 196 | function 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 | |
| 242 | function onlookupservice(err, hostname, service) { |
no test coverage detected