2

I want to write function in models to get user ip , and want to store in user table has column name ip_address in node js. (using express, mysql)

  User.prototype.userip= function(req, res)
  {
    // here need access to IP address here
  }
tkausl
  • 13,686
  • 2
  • 33
  • 50
malik
  • 41
  • 2
  • 8
  • Possible duplicate of [Express.js: how to get remote client address](https://stackoverflow.com/questions/10849687/express-js-how-to-get-remote-client-address) – Oliver Jan 25 '19 at 08:16

2 Answers2

6
req.connection.remoteAddress 

Try this

Noaman Ilyas
  • 655
  • 6
  • 12
2

I recommend you to use os API from os to get IPv4

var os = require('os');
var networkInterfaces = os.networkInterfaces();

console.log( networkInterfaces );

API from npm ip to get IPv4

var ip = require("ip");
console.dir ( ip.address() );