Comparing version 0.1.2 to 1.0.0
'use strict'; | ||
var ipMon = require('../index'); | ||
const IpMonitor = require('../index'); | ||
var watcher = ipMon.createWatcher(); | ||
const ipMonitor = new IpMonitor(); | ||
watcher.on('IP:change', function (prevIP, newIP) { | ||
console.log('Prev IP: %s, New IP: %s', prevIP, newIP); | ||
ipMonitor.on('change', (prevIp, newIp) => { | ||
console.log(`IP changed from ${prevIp} to ${newIp}`); | ||
}); | ||
/* | ||
Generic error event | ||
*/ | ||
watcher.on('error', function (error) { | ||
throw error; | ||
}); | ||
/* | ||
Seperate event for ip error handling. | ||
It will fire when the connection has been lost, e.g your router is restarting, | ||
thats why you may want to handle it differently than other errors. | ||
*/ | ||
watcher.on('IP:error', function (error) { | ||
console.log('Cant get external IP: ' + error); | ||
ipMonitor.on('error', (error) => { | ||
console.error(error); | ||
}); | ||
watcher.on('IP:success', function (IP) { | ||
console.log('Got IP: %s', IP); | ||
}); | ||
watcher.start(); | ||
ipMonitor.start(); |
'use strict'; | ||
var ipMon = require('../index'); | ||
const IpMonitor = require('../index'); | ||
var watcher = ipMon.createWatcher({ | ||
polling: 10000, | ||
externalIP: { | ||
const ipMonitor = new IpMonitor({ | ||
pollingInterval: 36000, | ||
verbose: true, | ||
externalIp: { | ||
timeout: 1000, | ||
getIP: 'parallel', | ||
services: ['http://ifconfig.co/x-real-ip', 'http://icanhazip.com/'], | ||
replace: true | ||
replace: true, | ||
verbose: true | ||
} | ||
}); | ||
watcher.on('IP:change', function (prevIP, newIP) { | ||
console.log('Prev IP: %s, New IP: %s', prevIP, newIP); | ||
ipMonitor.on('change', (prevIp, newIp) => { | ||
console.log(`IP changed from ${prevIp} to ${newIp}`); | ||
}); | ||
/* | ||
Generic error event | ||
*/ | ||
watcher.on('error', function (error) { | ||
throw error; | ||
}); | ||
/* | ||
Seperate event for ip error handling. | ||
It will fire when the connection has been lost, e.g your router is restarting, | ||
thats why you may want to handle it differently than other errors. | ||
*/ | ||
watcher.on('IP:error', function (error) { | ||
console.log('Cant get external IP: ' + error); | ||
ipMonitor.on('error', (error) => { | ||
console.error(error); | ||
}); | ||
watcher.on('IP:success', function (IP) { | ||
console.log('Got IP: %s', IP); | ||
}); | ||
watcher.start(); | ||
ipMonitor.start(); |
24
index.js
'use strict'; | ||
var Watcher = require('./lib/watcher').Watcher; | ||
var utils = require('./lib/utils'); | ||
var extIP = require('external-ip'); | ||
module.exports.createWatcher = function (extConfig) { | ||
extConfig = extConfig || {}; | ||
var isValid = utils.validateConfig(extConfig); | ||
if(isValid.errors.length) { | ||
throw new Error(isValid.errors); | ||
} | ||
var defaultConfig = { | ||
polling: 20000, | ||
externalIP: {} | ||
}; | ||
var config = utils.mergeConfig(extConfig, defaultConfig); | ||
var getIP = extIP(config.externalIP); | ||
return new Watcher(getIP, config); | ||
}; | ||
module.exports = require('./lib/Watcher'); |
{ | ||
"name": "ip-monitor", | ||
"version": "0.1.2", | ||
"version": "1.0.0", | ||
"description": "A node.js library to monitor your external ip", | ||
@@ -28,9 +28,8 @@ "main": "index.js", | ||
"dependencies": { | ||
"external-ip": "^0.2.0", | ||
"revalidator": "^0.2.0" | ||
"external-ip": "^2.0.3" | ||
}, | ||
"devDependencies": { | ||
"chai": "^1.9.1", | ||
"mocha": "^1.21.4" | ||
"chai": "^4.1.2", | ||
"mocha": "^5.0.4" | ||
} | ||
} |
@@ -1,2 +0,5 @@ | ||
#ip-monitor [![Build Status](https://travis-ci.org/J-Chaniotis/ip-monitor.svg)](https://travis-ci.org/J-Chaniotis/ip-monitor) [![Dependency Status](https://david-dm.org/j-Chaniotis/ip-monitor.svg)](https://david-dm.org/j-Chaniotis/ip-monitor) | ||
# ip-monitor | ||
[![Build Status](https://travis-ci.org/J-Chaniotis/ip-monitor.svg?branch=master)](https://travis-ci.org/J-Chaniotis/ip-monitor) | ||
[![dependencies Status](https://david-dm.org/j-Chaniotis/ip-monitor/status.svg)](https://david-dm.org/j-Chaniotis/ip-monitor) | ||
[![npm version](https://badge.fury.io/js/ip-monitor.svg)](https://badge.fury.io/js/ip-monitor) | ||
@@ -8,3 +11,3 @@ | ||
using [npm](https://www.npmjs.org/package/ip-monitor): `npm install ip-monitor` | ||
`npm install ip-monitor` | ||
@@ -14,34 +17,16 @@ ## Usage | ||
```javascript | ||
'use strict'; | ||
var ipMon = require('ip-monitor'); | ||
const IpMonitor = require('ip-monitor'); | ||
const ipMonitor = new IpMonitor(); | ||
var watcher = ipMon.createWatcher(); | ||
watcher.on('IP:change', function (prevIP, newIP) { | ||
console.log('Prev IP: %s, New IP: %s', prevIP, newIP); | ||
ipMonitor.on('change', (prevIp, newIp) => { | ||
console.log(`IP changed from ${prevIp} to ${newIp}`); | ||
}); | ||
/* | ||
Generic error event | ||
*/ | ||
watcher.on('error', function (error) { | ||
throw error; | ||
ipMonitor.on('error', (error) => { | ||
console.error(error); | ||
}); | ||
/* | ||
Seperate event for ip error handling. | ||
It will fire when the connection has been lost, e.g your router is restarting, | ||
thats why you may want to handle it differently than regular errors. | ||
*/ | ||
watcher.on('IP:error', function (error) { | ||
console.log('Cant get external IP: ' + error); | ||
}); | ||
ipMonitor.start(); | ||
watcher.on('IP:success', function (IP) { | ||
console.log('Got IP: %s', IP); | ||
}); | ||
watcher.start(); | ||
``` | ||
@@ -51,30 +36,42 @@ | ||
```javascript | ||
var watcher = ipMon.createWatcher({ | ||
polling: 10000, | ||
externalIP: { | ||
const IpMonitor = require('ip-monitor'); | ||
const ipMonitor = new IpMonitor({ | ||
pollingInterval: 36000, | ||
verbose: true, | ||
externalIp: { | ||
timeout: 1000, | ||
getIP: 'parallel', | ||
services: ['http://ifconfig.co/x-real-ip', 'http://icanhazip.com/'], | ||
replace: true | ||
replace: true, | ||
verbose: true | ||
} | ||
}); | ||
ipMonitor.on('change', (prevIp, newIp) => { | ||
console.log(`IP changed from ${prevIp} to ${newIp}`); | ||
}); | ||
ipMonitor.on('error', (error) => { | ||
console.error(error); | ||
}); | ||
ipMonitor.start(); | ||
``` | ||
##API | ||
### Configuration | ||
`ipmon.createWatcher([config])` accepts a configuration object with the following optional properties: | ||
* <b>`polling: <Integer>`:</b> how often to poll for ip changes, default 20000ms | ||
* <b>`externalIP: <Object>`:</b> configuration passed directly to [`external-ip`](https://github.com/J-Chaniotis/external-ip/blob/master/README.md) | ||
## Configuration | ||
`new IpMonitor([config])` accepts a configuration object with the following optional properties: | ||
* <b>`pollingInterval: <Integer>`:</b> how often to poll for ip changes, default 1 day | ||
* <b>`externalIp: <Object>`:</b> configuration passed directly to [`external-ip`](https://github.com/J-Chaniotis/external-ip/blob/master/README.md) | ||
### Methods | ||
## Methods | ||
* <b>`.start()`:</b> start watching | ||
* <b>`.stop()`:</b> stop watching | ||
* <b>`.poll()`:</b> poll for ip manually | ||
* <b>`.isWatching()`:</b> check if ip-monitor has started | ||
### Events | ||
* <b>`IP:success` :</b> fired every time `.poll()` yields an ip | ||
* <b>`IP:error`:</b> fired when `.poll()` encounters an error, usually if the connection is down | ||
* <b>`IP:change`:</b> fired when the external ip has changed. it will also fire the first time `.start()` or `.poll()` are invoked. | ||
## Events | ||
* <b>`change`:</b> fired when the external ip has changed. it will also fire the first time `.start()` or `.poll()` are invoked. | ||
* <b>`error`:</b> typical error handling here | ||
## Test | ||
Change your working directory to the project's root, `npm install` to get the development dependencies and then `npm test` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
0
8094
9
172
74
2
+ Addedcommander@5.1.0(transitive)
+ Addeddecompress-response@4.2.1(transitive)
+ Addedexternal-ip@2.3.1(transitive)
+ Addedmimic-response@2.1.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedsimple-concat@1.0.1(transitive)
+ Addedsimple-get@3.1.1(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removedrevalidator@^0.2.0
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcommander@2.20.3(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedevented-async-loop@0.1.1(transitive)
- Removedextend@3.0.2(transitive)
- Removedexternal-ip@0.2.4(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpsl@1.9.0(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedrevalidator@0.2.00.3.1(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)
Updatedexternal-ip@^2.0.3