如何在 nodejs 模型中获取用户 ip?并在我的表列 ip_address 中更新
Posted
技术标签:
【中文标题】如何在 nodejs 模型中获取用户 ip?并在我的表列 ip_address 中更新【英文标题】:How to get user ip in nodejs model ? and update in my table column ip_address 【发布时间】:2019-06-18 23:44:24 【问题描述】:我想在模型中编写函数来获取用户 ip ,并且想存储在用户表中,在节点 js 中有列名 ip_address 。 (使用快递,mysql)
User.prototype.userip= function(req, res)
// here need access to IP address here
【问题讨论】:
Express.js: how to get remote client address的可能重复 【参考方案1】:req.connection.remoteAddress
试试这个
【讨论】:
【参考方案2】:我推荐你使用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() );
【讨论】:
以上是关于如何在 nodejs 模型中获取用户 ip?并在我的表列 ip_address 中更新的主要内容,如果未能解决你的问题,请参考以下文章