Skip to content

eiriksm/node-local-ip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-local-ip

Build Status Code Climate

Get local ip address in node.

Installation

npm install local-ip

Why?

Well, for different kinds of reasons you might want to know what your local ip address is so you can broadcast it to different services.

API

localip(interface, [callback])

interface should be a network interface, such as wlan0. callback is optional, and will be invoked with the signature callback(err, res) if specified. If no callback is specified, the value will be returned directly, or an Error will be thrown in case of an error.

Example

var localip = require('local-ip');
var iface = 'wlan0';

localip(iface, function(err, res) {
  if (err) {
    throw new Error('I have no idea what my local ip is.');
  }
  console.log('My local ip address on ' + iface + ' is ' + res);
});

You can also use it in sync mode:

var iface = 'wlan0';
var localip = require('local-ip')(iface);
console.log('My local ip address on ' + iface + ' is ' + localip);

License

MIT

About

Get local ip address in node.

Resources

Stars

Watchers

Forks

Packages

No packages published