I have a Application Built on Node.js & Express with Mongodb(MEN).its working but i wanted to store the IP's from where my App is getting accessed more and for some other Info.i used diff npm modules But unable to get Client IP Address.instead of Client Address its giving public IP of Server where it is running on. My app Structure Looks like Below..
FIRST APP
My_APP_FOLDER|--> app------> views,models,controllers
|--> public---> js,css
|--> config---> routes.js
|server.js
|package.json
Express is intiated in server.js file var app = express();
and exported module.exports = app;
and i'm loading all routes.js , public files using require()
in sever.js file.
so whenever request comes it will hit routes.js
. it will check for matching /urlpath
and will execute the controller function. which is mentioned something like this app.get('/urlpath',contoller.functionname);
.
controller function will look like this
exports.index = function (req, res) {
//logic mentioned here
console.log(req.ip);//here im seeing public IP address of server where i hosted app instead client of IP address from where request has come.
});
and i tried same with other application. which is single file without multiple folders n files.
SECOND APP
var express = require('express');
var app = express();
app.get('/', function (req, res) {
// console.log(req.ip); and tried with some other modules too getting IP address of Client which is exactly what i need
});
So why i'm unable to get IP of Client in First App and why i'm getting in Second.any suggestions to get IP in First App.Thanks in Advance