Find Broken Link(fbl)_0.1

Safrin
3 min readSep 25, 2020

--

Hello, People! Another week, another blog! If you don’t know me yet and curious to know, take a look at my very first blog, This week’s blog is quite technical. It is a note to myself to mark my progress in my first attempt of making a command line tool. I made a command line tool using node.js. It checks URL to report if it is a good, bad, does not exist or unknown link.

First Phase: Make a Simple CLI

When I heard first time the word, command line tool, I was 99.99% sure I will scream at my laptop the whole week trying to figure it out. Fortunately, the google and node.js made it much easier. Here is the tutorial I used to get me started. I successfully made my CLI and named it fbl which is the acronym of find broken link.

Second Phase: Add Argument

Next phase is to manage arguments. One scenario is with no argument. In that case, I displayed message to let the user know that argument is required and how to use fbl.

Output of running fbl with zero argument

Another scenario is with argument which can be a file name or a single URL. I created two options: ‘-f’, ‘--fileName’ for file and ‘-u’, ‘ — url’ for url. Other options available are: ‘--help,’ ‘--version’ as you can see in the above picture.

Third Phase: Managing File

After adding the file options, the next step is to read the file and find the URL with http and https. I used line-reader library to extract and read the file line by line. I found this library useful as you are not responsible to track when you reach at the end of line or the file. To find the exact URL, I used `match` and stored the output in a array.

Final Phase: Checking the URL

Now we have our links from the file, let’s do the final step. I used `fetch` to get the response of URL. Upon receiving the status code of URL, four messages were displayed: good with status code` 200`, bad with status code `400` and `404`, not exist with URL that throws error, and last but not the least unknown with any other status codes. To make my output more reader friendly, I used chalk library.

Output of checking for a file
Output of checking for a single url

Install my CLI

Check my git repo and install it following README.md instructions. Any feedback is appreciated. It is my first time building CLI. Therefore, I am sure that mistake can be found but as we all know we learn best from our mistake. So, please point out any mistake or recommendation you have. I will add more features and improvement in future. Keep an eye on the repo. Until then, goodbye, friends!

--

--

Safrin
Safrin

No responses yet