Skip to main content

Command Palette

Search for a command to run...

Debugging Chronicles: My HNG Stage One Adventure

Published
3 min read
Y

I'm a full-stack software engineer with a passion for building software solutions and sharing my Knowledge. Figuring a lot of things out. These are my personal notes on my tech exploit. As I learn, I share.
When I'm not providing web services, I love providing guidance and mentorship to newbies starting their careers in tech. Let's have a conversation.

I was given a task to expose a URL for my HNG stage 1 task. Successfully submitting it would mean I get promoted to stage 2.

at first, I thought it would be a straightforward task but little did I know I would be in for a long ride.

The task was to get the location and weather of a client using their IP address and return a response in a specific format. We were instructed not to deploy using render.com.

I researched APIs for user location and weather, first trying a weather API and then using ipstack to get the IP address.

We then received further instructions to use only one API call. This meant I had to find an API that could return both the weather and location or find another way to get the IP address without making an API call.

I found an API that can use an IP address to return the weather and location

I built the program but I was getting weather for a city that didn't exist. ladies and gentlemen here started my journey into debugging. at first, I thought the problem was the API, so I tried writing it in a different format, that didn't work, so I tried a different API, which was not working too. I decided to take a break. I went back to Slack and was reading up comments by my colleagues in the backend track, some people were having issues too while others were submitting and making jokes. anxiety was setting in and the fear that this might not work out was constantly ringing in my head.

After taking a break and doing something else I came back for round two with a fresh set of eyes and ideas. while I was on break, the deadline for submission of the task was extended and that helped calm my nerves. after rewriting the code 4 different times, I decided to make the last one work, all or nothing.

The first thing I did was to comment the code out so that I could analyze each component separately. my application was doing three things,
1. get the client's IP address using my IP API
2. use the IP address to get the location and city
3. use the city to get the weather data and temperature from the weather API

After logging and testing various parts of the application, I found that the problem was from the IP address I got from my response, it was in the form [::1] which I found out was short for home address, the my-ip API does not accept that format, so added an if statement to use a static IP address whenever I get the IP in that format, and voila my problem was solved.

I was happy, thinking my problem was finished, turns out that was not the case. There is a common joke among developers that goes "It works on my machine", it's basically a response to the question "Why is your code not working in production".

I had the same challenge, someone suggested hosting my application using Vercel, I tried it initially and it didn't work, I tried hosting a different application, but that didn't work, it didn't help that the Vercel docs were bulky, and difficult to navigate for me. I looked at YouTube videos and still couldn't find a solution, so I decided to take another break.

I asked chatGPT for suggestions and I still couldn't figure it out, I went on Google and found a tutorial on how to host an app on Vercel, and I then figured the issue was from my vercel.json file. it turned out I got the routes wrong, I was able to fix it and everything was alright with the world again.