How to get ip of website visitor

How to get the ip of the website visitor? So I can see it in the console? I need it without JQuery.

Welcome to glitch! You can’t do it client-side. You’d have to do it server side for example make a request to a website, but to do it when a request comes through, it’s pretty simple! This code gets the job done:

const express = require("express");
const app = express();
app.get("/", (req, res) => {
    const IP = req.headers["x-forwarded-for"].split(",")[0];
    console.log(IP); // logs the ip in server console
    res.send(IP); //sends the IP back to the client
});

app.listen(3000);

When you visit / you should get sent back your IP like:

(wrote this quickly on mobile)

thanks! You are good!

1 Like