0

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!

1
  • what kind of output do you get from your own code ? Commented Jun 30, 2017 at 21:40

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.