I am passing string from client side and if that string is part of that file content i want to print that line , is it doable using fs and nodejs ?
searvice.js
var fs = require('fs');
var path = require('path');
var async = require('async');
var searchStr;
function readFile(str){
searchStr = str;
// var url = './logs/St/server1.log';
fs.readFile('./logs/St/server1.log', 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
console.log('Server Data',data);
inspectFile(data);
});
}
function inspectFile(data) {
if (data.indexOf(searchStr) != -1) {
// do something
console.log('print the matching data');
}
}
exports.readFile = readFile;