external-ip
Advanced tools
Comparing version 1.3.0 to 1.3.1
'use strict'; | ||
var getIP = require('../index')(); | ||
const getIP = require('../index')(); | ||
getIP(function (err, ip) { | ||
getIP((err, ip) => { | ||
if (err) { | ||
@@ -10,2 +10,2 @@ throw err; | ||
console.log(ip); | ||
}); | ||
}); |
'use strict'; | ||
var extIP = require('../index'); | ||
const extIP = require('../index'); | ||
var getIP = extIP({ | ||
const getIP = extIP({ | ||
replace: true, // true: replace the default services list, false: extend it, default: false | ||
services: ['http://ifconfig.co/x-real-ip', 'http://ifconfig.io/ip'], | ||
services: ['http://icanhazip.com/', 'http://ident.me/'], | ||
timeout: 600, // set timeout per request, default: 500ms | ||
'getIP': 'parallel' | ||
getIP: 'parallel' | ||
}); | ||
getIP(function (err, ip) { | ||
getIP((err, ip) => { | ||
if (err) { | ||
@@ -17,2 +17,2 @@ throw err; | ||
console.log(ip); | ||
}); | ||
}); |
{ | ||
"name": "external-ip", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "A node.js library to get your external ip from multiple services", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -31,3 +31,2 @@ # external-ip | ||
``` | ||
with configuration | ||
@@ -56,2 +55,42 @@ | ||
``` | ||
### Promises | ||
The API of this library is designed around the classic node.js error-first callback. | ||
As of node.js V8, converting this type of callback into a promise is pretty straight forward and | ||
requires one more line of code. | ||
basic | ||
```javascript | ||
'use strict'; | ||
const {promisify} = require('util'); //<-- Require promisify | ||
const getIP = promisify(require('external-ip')()); // <-- And then wrap the library | ||
getIP().then((ip)=> { | ||
console.log(ip); | ||
}).catch((error) => { | ||
console.error(error); | ||
}); | ||
``` | ||
with configuration | ||
```javascript | ||
'use strict'; | ||
const { promisify } = require('util'); //<-- Require promisify | ||
const getIP = promisify(require('external-ip')({ | ||
replace: true, | ||
services: ['http://icanhazip.com/', 'http://ident.me/'], | ||
timeout: 600, | ||
getIP: 'parallel', | ||
verbose: true | ||
})); // <-- And then wrap the library | ||
getIP().then((ip) => { | ||
console.log(ip); | ||
}).catch((error) => { | ||
console.error(error); | ||
}); | ||
``` | ||
If you believe this extra step shouldn be there, feel free to open an issue and/or a pull request | ||
## Configuration | ||
@@ -58,0 +97,0 @@ |
@@ -6,4 +6,3 @@ more tests | ||
eliminate nasty IFs | ||
verbose mode | ||
24385
19
461
158