nodejs get user ip - NaClYen/blog GitHub Wiki

code

import fetch from "node-fetch";

let userIP = "localhost";
await fetch("https://api.ip.sb/ip")
  .then((res) => res.text())
  .then((result) => (userIP = result));

console.log(`ip is ${userIP}`);

output

ip is 10.24.61.188

ref