local-ip

2.0.0 • Public • Published

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')(interface);
console.log('My local ip address on ' + iface + ' is ' + localip);

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i local-ip

Weekly Downloads

4,196

Version

2.0.0

License

MIT

Last publish

Collaborators

  • eiriksm