File Searcher

Background

Computers contain a lot of data: text, video, even software. With increasing data, it is easy to misplace files, especially when using nested folders. The directory’s hierarchy may be somewhat like this.

Finding a file manually is exhausting, particularly if the folders keep nesting down. It is even worse when you forget the name of the file. Then, you have to open every file in every folder!

Introduction to file searcher

Nowadays, all operating systems come with the ability to search for files. In Linux, people can use commands from a terminal such as find, to search for a file/directory, or tree, to get a birds-eye view of the directory’s structure. These commands are great if you know what you’re looking for. However, if you’re not totally sure, grep is more useful.

The grep command searches for a certain keyword or pattern in a specified directory and tells which files contain the targeted content. It is an ideal command when looking for files or to confirm if a text exists in some directory. It can recursively traverse all sub-folders in the directory to check the content of files within.

In this project, we work on something similar to grep; we will make our own file searcher in JavaScript asynchronously.

Problem Statement

Your local supermarket "Please Buy?" has gone entirely digital. They maintain logs, receipts, and everything else on a computer. Despite the IT guy’s best effort, the files and folders are getting messy and things get lost. Given this problem, the IT guy wrote a program that gets directories of files and the line number within those files for a certain string token. The IT guy implemented a functional but slow, synchronous solution. To boost your ego, you decide to re-write the program in JavaScript to make it faster via asynchronous programming.

Task

Use your JavaScript knowledge to implement the solution. When given the path to a directory and target string token, it should return an object with keys as pathname and values as an array of line numbers in which the string token matches. The solution will leverage asynchronous programming.

Keeping the complexity of directories in mind, provide a solution to this task. Good Luck!