From 24d92562c35812e4d00cae8bd0bd49f936f49f2e Mon Sep 17 00:00:00 2001 From: Adan Toscano Date: Tue, 10 Oct 2023 17:49:52 +0100 Subject: [PATCH] feat: add function to search --- src/services/check-string-in-file.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/services/check-string-in-file.js diff --git a/src/services/check-string-in-file.js b/src/services/check-string-in-file.js new file mode 100644 index 0000000..40d950c --- /dev/null +++ b/src/services/check-string-in-file.js @@ -0,0 +1,17 @@ +import * as fs from 'fs'; +import * as readline from 'readline'; + +export default async function(stringToCheck, filePath) { + const reader = readline.createInterface({ input: fs.createReadStream(filePath) }); + let exists = false; + + for await (const line of reader) { + console.log(line); + if(line===stringToCheck) { + exists = line===stringToCheck + break; + } + } + + return exists; +} \ No newline at end of file