I'm trying to do something with node.js and express . but I face some problem in express passing variable to .js
here is my code , I want to know the IP address in the .js , so I do the following things
like this , I redirected the user to the test.js
app.get('/', function(req, res) {
app.set('ipAddr' , req.ip);
res.sendfile(__dirname + '/index.html');
});
and index.html include
<script src="/hello.js"></script>
so , in the hello.js , I want to know the client IP address.
I try to find out how to do it , but I fail.
can anyone tell me how to do it ? really thanks.
the IP of client, can be found at req.connection.remoteAddress you can either pass the variable with res.render to a page, or use res.send