How to determine the user IP address using node.js ?
dns.lookup(hostname[, options], callback)
- Hostname: It consists website link which is valid or active.
- Option: Default value is 0. It can be 0, 4 or 6 which indicates IPv4 and IPv6 addresses.
- Callback: This function has user’s IP address and family(i.e. IPv4 and IPv6) and error.
Approach to determine IP address:
- Import dns module in the node.js file.
- Use dns.lookup() function to search for addresses and family of the client.
- Display address and family.
Run index.js file using the below command: