currently i'm trying to do some post req into my server (made with express) and my goal is when the user input something in the field (like a simple search) i receive this in the req.body and check it inside the file to see the match like the example below:
CFH303 MUS7404 - CFH304 MUS7404 - CFH305 CSO7918 - CFH306 GCN7127 - CFH307 MEN7108 - CFH308 MEN7022 - CFH309 PSI7403 - CFH310 GCN7123
Each of these bold text is the result that i'm looking for, the input will be the itallic text and i must return the bold one. My file does not have more than one string in the same line, they are line by line (the hypens i made here in stack to better view).
I found other question but it's on fs.createReadStream is it a better approach? Because in my mind makes zero sense receive them one by one.
My route, here i was trying to do some kind of array but i notice the \n pushing togheter
router.post('/getIdDisciplina', function(req, res, next){
let idDisc = req.body.IdDisc;
let fileSize = fs.statSync('arqex.txt').size;
console.log(idDisc);
fs.open('arqex.txt', 'r', function(err, fd){
if (err) throw err;
else{
fs.readFile('arqex.txt', 'utf8', function(err, data){
if (err) throw err;
else{
//let aux = []
//aux.push(data)
//console.log(aux);
}
});
fs.close(fd, (err) =>{
if (err) throw err;
});
}
});
res.render('index');
});
Thanks for the time!