2017-06-30 1 views
0

を実行含まれている場合、私は次のスクリプトがありますNodeJS文字列がスクリプト

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); 

を、私は文字列が含まれている場合にのみJavaScriptを実行したい「警告:!見つかりました」

スクリプト:

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!'); 
}); 

ヘルプ!

+0

あなたは自分のコードからどのような出力を得ていますか? –

答えて

0

2つを組み合わせる方法を尋ねていますか?

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); 
+0

はい、どうもありがとう! – user3130478