Skip to content

How to get My PUBLIC IP address Using Node js

I want to get my Public IP address using Node js only

For example when i search on Google “What is my Ip address “

Gives me output like 10X.XX.XX.XXX

How to get this Ip address Using node js without importing any Libraries like ip , Public-ip etc …

I want to write my Custom Code to get public ip Without sending requests to other websites like , etc …


const { exec } = require('child_process')

exec('curl', function(error, stdout, stderr){
    console.log('your ip is :'+ stdout);

you could run a command and get the output like curl or ping

enter image description here