簡體   English   中英

如何在nodejs模型中獲取用戶ip? 並在我的表格列ip_address中更新

[英]How to get user ip in nodejs model ? and update in my table column ip_address

我想在模型中編寫函數以獲取用戶ip,並希望存儲在用戶表中的節點js中具有列名ip_address。 (使用express,mysql)

  User.prototype.userip= function(req, res)
  {
    // here need access to IP address here
  }
req.connection.remoteAddress 

嘗試這個

我建議您使用來自os os API來獲取IPv4

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

console.log( networkInterfaces );

來自npm ip API獲取IPv4

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM