NODEJS get ip address node.js - Net-Raft.com

Welcome aboard! We are happy you are here and wish you good net-raft!




Just a Web Code Solution

How to get client ip address using node.js


 913

NODEJS


3

// at first you install "npm install ip" in node.js command prompt

//put this code into getip.js
var http = require('http');
var ip = require('ip');

var srv = http.createServer(function (req, res) {
var address = ip.address();

res.writeHead(200, {'Content-Type': 'text/plain'});
res.end(address);

});

srv.listen(3000);
console.log("Listening to Port 3000");

// type "node getip.js" in command prompt
// then put this url "http://localhost:3000/address" into any browser


By     Created   
The power of the user (%)
63%

NODEJS


2

// type "node script.js" in node.js command prompt

// place into script.js

var os = require('os');

var interfaces = os.networkInterfaces();
var addresses = [];
for (var k in interfaces) {
for (var k2 in interfaces[k]) {
var address = interfaces[k][k2];
if (address.family === 'IPv4' && !address.internal) {
addresses.push(address.address);
}
}
}

console.log(addresses);


By     Created   
The power of the user (%)
36%

NODEJS


0

// this node.js code put into app.js

const request = require('request')

request('http://ipinfo.io ' , function(error, res, body) {
var ipuser = JSON.parse(body)
console.log(ipuser.ip)
})

// then type "node app.js" in command prompt


By     Created   
The power of the user (%)
9%

NODEJS


-1

var os = require( 'os' );

var networkInterfaces = os.networkInterfaces( );

console.log( networkInterfaces );


By     Created   
The power of the user (%)
5%



The most helpful NODEJS solutions

get user ipget user ipNODEJS

Click to see more ...

  4.7K     1.7K

how to get client netmask using node.js ?how to get client netmask using node.js ?NODEJS

Click to see more ...

  2.3K     558

How to get client machine name and computer name with node.js?How to get client machine name and computer name with node.js?NODEJS

Click to see more ...

  2.2K     423

how to get client local ip address using node.js ?how to get client local ip address using node.js ?NODEJS

Click to see more ...

  1.2K     311

How to get client ip address using node.jsHow to get client ip address using node.jsNODEJS

Click to see more ...

  913     268

How to combine node.js and jquery ?How to combine node.js and jquery ?NODEJS

Click to see more ...

  675     247

how to detect tablet, iPad, iPhone, Android and Blackberry using nodejs ?how to detect tablet, iPad, iPhone, Android and Blackberry using nodejs ?NODEJS

Click to see more ...

  906     138

get real user ip address using node.js?get real user ip address using node.js?NODEJS

Click to see more ...

  379     123

get client region using node.js ?get client region using node.js ?NODEJS

Click to see more ...

  288     118

how to update a record in mysql using node.js ?how to update a record in mysql using node.js ?NODEJS

Click to see more ...

  283     115