Could someone please let me know how to get public IP address of the client machine using JavaScript or typescript?
Thanks & Regards, Ajay
Could someone please let me know how to get public IP address of the client machine using JavaScript or typescript?
Thanks & Regards, Ajay
This is the most basic configuration. and its only for learning purposes. please take the time to read and learn about running server with node js. the risks and how to protect.
var express = require("express");
var app = express();
app.get("/", (req, res) => {
console.log(req.ip);
res.status(200).json({ userIp: req.ip });
});
var listener = app.listen(8080, function () {
console.log("Listening on port " + listener.address().port);
});
you need to install express. put this code in the app.js.
after running the server any request to '/' will return json with the user ip.
on local host you will get something like ::1 but if you will upload it to a server you will get the right result.
in this case calling loaclhost:8080/
will return the user's ip.