Release 0.1 Complete!
Guys, gals and non binary pals we have done it! Release 0.1 version 0.0.0 is complete and I have to say, it wasn’t as bad as I thought. Let me run you through what I did.
So if you read the last story I told you about the tutorial I found online. If you haven’t seen that story or the tutorial then check it out, it’s great. Anyway, picking up from where we left off, I managed to get arguments built in. I also got chalk and for colours. It was now a matter of putting it all together and I did this through 4 arrays
First Array
I did was use the fs.readFile function to get the file, then I split it at each like where a \n was found and put it into the array lineArray.
This would allow me to separate each line into a single element in an array where it would be passed into the next array.
Second Array
This Array is used to seperate lines that do not have links with lines that do. This would speed things up for our final operation as we wouldn’t want to check those lines. We also won’t waste time on those using our regex on them.
Third Array
This third array is where our regex comes in, it checks how many individual URLs there are in the file, so if a line had say: three URLs, then this array would have 3 elements for each URL.
Fourth and Final Array
The fourth and final array is where the magic happens. Here we can see 2 for loops, the first for loop checks for unique URLs so that we only check them once. This ensures that websites wont mistake us for DDoS-ing them if we have something like 20 of the same links in this file. This also cuts down on the time it takes for us to run the final part which can be seen below. The second for loop checks for system URLs that may be embedded in .pdf and .doc files. This for loops removes it from them so we wont be checking links that we didn’t put in our files. Finally is the asynchronous checking which uses the fetch dependency to find the status codes of each URL. We only check the HEAD method since that’s all we care about.
So in this block try and catch block we check the head if the status returns 200 which means good which we mark in bright green. If it returns 400 or 404 we display that in the console as a bright red bad, any other error code returns a unknown and timeouts, DNS and other errors will be in a dark red. It may take a while at the end as it waits a maximum of 13 seconds before making things as a timeout. This value can be changed if you download the file but you may get more timeout errors on links that would normally be good.
And that’s pretty much it for the Release 0.1! You can find it here on my github if you wish to try it out yourself. My next story will be about how me and my partner for lab 0.1 tried to debug each other’s release 0.1. Thanks for tuning in again! And I will see you soon.