DEV Community

just n&&f
just n&&f

Posted on

How I faced my first backend bug.

Ponder this: You write a script that implements a certain operation in the morning, shut down your system, take a breather, and try to run that script again and it doesnt work?
This is a story of how I implemented a login authentication using nodejs + express. When I tried the previously working authentication later that day and it didn't run.
So here is the gist, I am trying to implement a simple login and register functionality with nodeJS + expressJS + MONGODB using a simple concept of GET request, POST request to the database, GET request for the routing and POST request when I need to send the data to the database (MONGODB), so I started off by installing express and all the needed technologies that were required for my applicaton such as (express-ejs-layouts, bcrypt, mongdb, mongoose, dotenv e.t.c), so after installing this I named my routes so I can see the pages I designed for the login and register page, I kind of like my Frontend creativity maybe because I started off as a Frontend Engineer, Anyways I began setting up the Schema's (that is the database field's that holds the register User data and login User data ( separately obviously). The first issue I ran into here was the fact that the nodemon (nodemon-for restarting my application automatically when a change is initialised) I installed minutes ago got a new update so my server went down shockingly....so I had to run "npm install -g nodemon" again to get the latest nodemon. So onto the problem that shocked my life so I wrote the script that post the User data to the database, I then ran the server, tested the login and register and it worked mind you I spent about 3-4 hours on this little task, because it was the first task I gave to myself as a backend engineer, the whole process worked, I double checked because it was kind of a milestone in this little journey I started so I took a breather, 2 hours later I came back to my codebase to continue doing a small dashboard for the users I noticed that my server wasn't running after about two hours of thinking and sighing I realized that my IP address had changed and because of this the connection I made using mongoose (for mongoDB) wasn't going through I fixed that, A novice like me I thought that backend bugs only come once and you'd be able to fix them by changing one line of code, backend bugs comes in pairs guys, they come in pairs!!! The problem that came up again was that I had to re-connect my mongoDB with mongoose again this included me deleting my previous database and creating a new database and then making my connection using mongoose again, It was at this point it worked. I learnt that in backend you need to take your time to understand every single line of code you write, the first time I made the connection I kind of rushed the whole process because I was following a tutorial and I was also asking questions on stackoverflow because I don't fully trust all this youtube tutorials people so it was when I took my time to understand the whole concept of using mongoose and when to use it that I got the connection right and my server worked.
check out https://hng.tech/internship, https://hng.tech/hire, to get update concerning jobs opportunities.

Top comments (2)

Collapse
 
kelvin_tops profile image
Kelvin Tops

This is beautiful. You're such a creative and patient person. I admire your passion towards web development. The sky is definitely the starting point .

Collapse
 
nweke_19 profile image
just n&&f

Thank you sir