I'd like to know whether a specific string is within the other strings or not, in Javascript(node js). Here is my code.
let findFromLog = function(req, res) {
const smsBeacon = req.body.SMS;
const callBeacon = req.body.CALL;
const phoneBeacon = req.body.PHONE;
let index = 0;
var logArray = [];
fs.readFile('./logs/winston-test.log', 'utf8', function(err, data) {
if (err) throw err;
var array = data.toString().split('\n\n');
for(var i in array) {
if (array[i].includes(smsBeacon)) {
logArray.push(array[i]);
} else if (array[i].includes(callBeacon)) {
logArray.push(array[i]);
} else if (array[i].includes(phoneBeacon)) {
logArray.push(array[i]);
}
}
// res.json({response : array});
});
res.json({response : logArray});
};
the variable 'array' has these contents.
"2020-01-27T08:19:53.625Z [winston-test] info: 220.94.1.121 - - [27/Jan/2020:08:19:53 +0000] \"GET /opensource/uploads/beam_1_SMS.jpg HTTP/1.1\" 404 841 \"-\" \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36\"",
"2020-01-27T08:19:55.404Z [winston-test] info: 220.94.1.121 - - [27/Jan/2020:08:19:55 +0000] \"GET /favicon.ico HTTP/1.1\" 404 2025 \"https://myserver/opensource/uploads/Object_1.jpg\" \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36\"",
"2020-01-27T08:20:45.257Z [winston-test] info: 220.94.1.121 - - [27/Jan/2020:08:20:45 +0000] \"POST /opensource/findFromLog HTTP/1.1\" 200 609 \"-\" \"PostmanRuntime/7.22.0\"",
"2020-01-27T08:21:23.336Z [winston-test] info: 220.94.1.121 - - [27/Jan/2020:08:21:23 +0000] \"POST /opensource/findFromLog HTTP/1.1\" 200 15 \"-\" \"PostmanRuntime/7.22.0\"",
"2020-01-27T08:22:29.801Z [winston-test] info: 110.70.14.56 - - [27/Jan/2020:08:22:29 +0000] \"POST /opensource/findFromLog HTTP/1.1\" 200 29 \"-\" \"okhttp/3.12.0\"",
"2020-01-27T08:28:11.399Z [winston-test] info: 220.94.1.121 - - [27/Jan/2020:08:28:11 +0000] \"POST /opensource/findFromLog HTTP/1.1\" 200 15 \"-\" \"PostmanRuntime/7.22.0\"",
"2020-01-27T08:28:13.399Z [winston-test] info: 220.94.1.121 - - [27/Jan/2020:08:28:13 +0000] \"POST /opensource/findFromLog HTTP/1.1\" 200 15 \"-\" \"PostmanRuntime/7.22.0\"",
"2020-01-27T08:31:11.957Z [winston-test] info: 220.94.1.121 - - [27/Jan/2020:08:31:11 +0000] \"GET /uploads/Object_2.jpg HTTP/1.1\" 404 2025 \"-\" \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36\"",
"2020-01-27T08:31:21.434Z [winston-test] info: 220.94.1.121 - - [27/Jan/2020:08:31:21 +0000] \"GET /uploads/Object_3.jpg HTTP/1.1\" 404 2025 \"-\" \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36\"",
"2020-01-27T08:33:23.213Z [winston-test] info: 110.70.14.56 - - [27/Jan/2020:08:33:23 +0000] \"POST /opensource/findFromLog HTTP/1.1\" 200 15 \"-\" \"okhttp/3.12.0\"",
""
I want to know the 'array' contains the strings a.k.a 'Object_1.jpg','Object_2.jpg', 'Object_1.jpg'. These jpg values are sent from the body (SMS, CALL and PHONE). So i used 'includes' but, it didn't work. I mean, the 'logArray' array had no value at the end of code (res.json~~).
Could you tell me what is the problem in my code?