![](/img/trans.png)
[英]How to get local IP address of user connected through request - Nodejs
[英]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 );
var ip = require("ip");
console.dir ( ip.address() );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.