Back to Basics: Battling A Debug Depression On My First Job as a Backend-Developer.

Back to Basics: Battling A Debug Depression On My First Job as a Backend-Developer.

A Backend-Developer debugging story on sending and receiving email with Nodejs and Typescript.

Behind The Scene:

As I recently finished my Tech training at a coding hub, I was thrilled to land my first job as a backend developer at a tech company. I learned MERN stack web development and was excited to put my skills to use in a real-world setting. However, as soon as I started my job, I quickly realized that debugging was a lot more difficult than I had anticipated. At first, I spent hours poring over lines of code, trying to find the source of a bug. I would get frustrated when I couldn't figure it out and would become demotivated as a result. The more I struggled with debugging, the worse I felt about my ability as a developer. I began to feel like I wasn't cut out for the job and that I had made a mistake in pursuing a career in technology. As the days went by, my morale continued to plummet. I found myself procrastinating and avoiding difficult debugging tasks, which only made my situation worse. I knew I needed to break out of this cycle, but I didn't know how.

One day, my tech lead noticed that I was struggling and asked to speak with me privately. I was initially nervous, thinking I was in trouble, but my tech lead reassured me that I wasn't. Instead, my Lead shared his experience with debugging when he first started as a developer. He explained that debugging was one of the most challenging aspects of software development and that developing the skills needed to be proficient at it took time. The conversation was a turning point for me. I realized that I wasn't alone in these struggles and that it was customary to feel frustrated when debugging. I began to take a step back and look at my debugging tasks more objectively. I started to break the problem down into smaller pieces and take a systematic approach to solving them. With time and practice, my debugging skills improved. I realized that it wasn't about being able to solve a bug on the first try but rather about having the persistence to keep trying and the patience to work through complex problems.

Looking back, I am grateful for my Tech-lead's words of wisdom and the opportunity to learn and grow as a developer. He knows that debugging will always be a challenging part of my job, but he also knows that I have the skills and the resilience to overcome any challenge that comes my way.

Introduction:

As a backend developer, debugging code is essential to the job. In this post, I'll share a story about how I encountered a challenging issue with sending and receiving emails using Typescript, Nodejs, and Nodemailer on an application my team and I were working on. We'll discuss the debugging process and the ultimate solution to the problem.

Background:

As a backend developer, I worked on a Node.js and Typescript application with an email feature. The application was supposed to send and receive emails, but it wasn't working as expected. I had spent hours trying to debug the issue but could not find the root cause of the problem. I was able to resolve the error using Javascript. However, I kept facing errors when using Typescript because I was new to it.

Debugging Process:

I began by examining the email code line by line, but I could not find any issues. I then turned to the application logs and found some error messages that were too vague to provide helpful information.

I decided to take a break and get some fresh air. It was during this break that my colleague suggested checking the configuration files. I realized I hadn't checked the configuration files, and sure enough, there was a small typo causing the problem all along.

Solution:

I fixed the typo in the email configuration, and the email feature started to work correctly. I was amazed at how such a simple solution had taken so long to find.

Sending Emails:

  • Install Nodemailer

Nodemailer is an open-source library that makes sending emails from Node.js applications easy. To use Nodemailer, you need to install it by running the following command in your terminal:

npm install nodemailer @types/nodemailer
  • Import Nodemailer

Once you have installed Nodemailer, you need to import it into your TypeScript file using the following code:

import nodemailer from 'nodemailer';
  • Set Up A Transporter

To send an email, you need to set up a transporter. The transporter is responsible for delivering your email to the SMTP server. You can set up a transporter using the following code:

Note: If you use Gmail as your mail, you get your password from either Google Oauth or Gmail.

const transport = nodemailer.createTransport({
  host: "smtp.gmail.com",
  port: 465,
  secure: true, // use SSL
  auth: {
    user: your_email@example.com',
    pass: 'your_password,
  },
});
  • Create an Email Object

Now that you have set up a transporter, you must create an email object containing the information you want to send. You can create an email object using the following code:

const mailOptions = {
  from: 'your_email@example.com',
  to: 'recipient_email@example.com',
  subject: 'Test Email',
  text: 'This is a test email from Node.js'
};

Replace the from, to, subject, and text fields with the appropriate values for your email.

  • Send the Email

Finally, you can send the email using the `transporter.sendMail()`method:

transporter.sendMail(mailOptions, (error, info) => {
  if (error) {
    console.log(error);
  } else {
    console.log('Email sent: ' + info.response);
  }
});

If the email is sent successfully, you should see the message "Email sent" in the console and, you should get an email notification.

Lessons Learned:

The most valuable lesson that I learned from this experience is always to check the configuration files first when debugging a problem. It's easy to get lost in the code and logs, but sometimes, the solution is much simpler than we think.

Conclusion:

Debugging is essential to any developer's job, and it can be challenging and time-consuming. However, by staying focused and trying different solutions, we can eventually find the root cause of the problem. In my case, it was a small typo that caused a significant issue, but by checking the configuration files, I solved the problem quickly.

Thank you☺

Did you find this article valuable?

Support Ihuoma Goodluck Ogbonna by becoming a sponsor. Any amount is appreciated!