Reputation: 217
I have a the following script:
function execute(){
require("fs").readFile("sometextfile.txt", function(err, cont) {
if (err)
throw err;
console.log("ALERT:"+(cont.indexOf("mystring")>-1 ? " " : " not ")+"found!");
});
}
setInterval(execute,9000);
I want to execute a javascript only if the string contains "Alert: found!"
The script:
var Prowl = require('node-prowl');
var prowl = new Prowl('API');
prowl.push('ALERT', 'ALERT2', function( err, remaining ){
if( err ) throw err;
console.log( 'I have ' + remaining + ' calls to the api during current hour. BOOM!' );
});
Help!
Upvotes: 0
Views: 817
Reputation: 60143
Are you asking how to combine the two?
const fs = require('fs');
const Prowl = require('node-prowl');
const prowl = new Prowl('API');
function alert() {
prowl.push('ALERT', 'ALERT2', function(err, remaining) {
if (err) throw err;
console.log('I have ' + remaining + ' calls to the API during current hour. BOOM!');
});
}
function poll() {
fs.readFile('sometextfile.txt', function(err, cont) {
if (err) throw err;
if (cont.indexOf('mystring') !== -1) {
alert();
}
});
}
setInterval(poll, 9000);
Upvotes: 1