Today my mind got blown

While coding randomly because i was stuck in a starbucks a friend of mine told me i should read the following articles after reviewing my github code. They kinda blew my mind and made me realize i have been doing a clustermess when i write javascript(Node i don’t do it professionally almost ever).First mistake using the top level namespace for all my functions. Thefore he pointed me to the following article which made a pretty deep impact and solved my problem.

Second one was my bit of code could be imported and would work sometimes. He pointed me to this article on writing modular js that honestly points to what im doing from now on.

Not adding much new here but recommending this as must read.
Will post my code from before and after applying this.