如何在nodejs模型中获取用户ip?并在我的表格列ip_address中更新

mal*_*lik 2 node.js express

我想在模型中编写函数以获取用户ip,并希望存储在用户表中的节点js中具有列名ip_address。(使用express,mysql)

  User.prototype.userip= function(req, res)
  {
    // here need access to IP address here
  }
Run Code Online (Sandbox Code Playgroud)

小智 6

req.connection.remoteAddress 
Run Code Online (Sandbox Code Playgroud)

尝试这个