<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Christian Mbah</title>
    <description>The latest articles on DEV Community by Christian Mbah (@chrismbah).</description>
    <link>https://dev.to/chrismbah</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1282011%2F3599b5f3-1c13-4a7b-a46a-eb45e9e4c467.jpeg</url>
      <title>DEV Community: Christian Mbah</title>
      <link>https://dev.to/chrismbah</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/chrismbah"/>
    <language>en</language>
    <item>
      <title>How Developers Flatline Their Careers — And How to Avoid It</title>
      <dc:creator>Christian Mbah</dc:creator>
      <pubDate>Sat, 06 Dec 2025 18:59:27 +0000</pubDate>
      <link>https://dev.to/chrismbah/how-developers-flatline-their-careers-and-how-to-avoid-it-6li</link>
      <guid>https://dev.to/chrismbah/how-developers-flatline-their-careers-and-how-to-avoid-it-6li</guid>
      <description>&lt;p&gt;Software engineering is one of the most interesting career paths in the world today. In an ecosystem where technologies like artificial intelligence are becoming mainstream every day, it’s no wonder you probably ventured into it out of curiosity, learned tirelessly, and began building a career. Yes, it’s exciting and full of possibilities, but it can also be surprisingly stagnating if you don’t know the right steps to take.&lt;/p&gt;

&lt;p&gt;Why? Because software engineering is simply a path, and how you navigate it determines how far you go. For some, it may be a smooth upward slope, steadily rising toward impact and financial freedom. For others, a series of peaks and valleys, a rollercoaster of wins and failures. But for some, there’s an initial rise… followed by a long, flat line.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgtulekid8zx6quz3l77f.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgtulekid8zx6quz3l77f.jpg" alt="Flatlining career software engineer" width="512" height="348"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In medical terms, flatlining means death; in software engineering, it means stagnation. The good news is stagnation isn’t permanent and with awareness, deliberate action, and the right mindset, growth is always possible. So here are 5 ways developers unintentionally flatline their careers, and how to avoid them:&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Avoiding Communication
&lt;/h2&gt;

&lt;p&gt;You might be able to write bug-free code that works flawlessly, but if you can’t explain your decisions, ask the right questions, or even collaborate effectively, no one will notice. Soft skills aren’t optional in this field; they are the piece that turns programmers into problem solvers with a meaningful impact.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqoe84aioujl1a7s15cpu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqoe84aioujl1a7s15cpu.png" alt="Software engineers communicating" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Brilliant engineers can stagnate for years simply because they couldn’t articulate their thoughts or navigate team dynamics because they lack communication skills. I could even argue being invisible in a team is worse than making a mistake, because mistakes are noticed, corrected, and learned from, meanwhile if you're invisible, you're invisible. If you want to stunt your career progress, then reduce communication as much as possible.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Relying on AI to Think for You
&lt;/h2&gt;

&lt;p&gt;AI is powerful — insanely powerful, but the truth is that AI only accelerates people who already think well. If you lack fundamentals, AI will become a crutch, not a jetpack.&lt;/p&gt;

&lt;p&gt;Rely on AI for every decision and your problem-solving muscles slowly deteriorate. You stop breaking down problems, thinking about design, and understanding why things work. Before you know it, you can generate code, but you can’t debug it… you can ship features, but you can’t explain them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp5rfpdef6r36tql5b792.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp5rfpdef6r36tql5b792.png" alt="AI vs Human thinking in software engineering" width="340" height="202"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;AI should be your partner, not your brain’s replacement. So if you want your growth to flatline instantly, fully outsource your thinking to AI.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Avoiding Project Ownership
&lt;/h2&gt;

&lt;p&gt;There’s a reason people can write code for years and still be seen as “junior.” It’s not skill. It’s not intelligence. It’s ownership. Developers who grow take responsibility for outcomes, not just tasks. They speak up, form opinions, and challenge decisions respectfully. They propose solutions instead of waiting for instructions.&lt;/p&gt;

&lt;p&gt;But refusing ownership? That’s the fastest path to staying invisible. You become the person who “just does what they’re told,” and you get treated accordingly.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn1403hyp7pi386g7dlk2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn1403hyp7pi386g7dlk2.png" alt="Junior vs senior dev" width="800" height="670"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So if your goal is to remain small forever, avoid ownership at all costs. If not, start taking responsibility.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Not Understanding the Business
&lt;/h2&gt;

&lt;p&gt;You don't get employed to write code, you get employed to create an impact &lt;em&gt;by&lt;/em&gt; writing code. Engineers who grow fast understand one thing: the business drives everything. Who are we building this for? What problem does it solve? Why does it matter? How does it affect revenue, users, cost, performance, or experience?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnkxse8g9gzm68w1pq7iu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnkxse8g9gzm68w1pq7iu.png" alt="Business in tech" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you understand why something matters, your decisions get sharper, your communication gets clearer, and your contributions get noticed. Seniority is basically the ability to connect code to outcomes.&lt;/p&gt;

&lt;p&gt;On the other hand, if you want to remain easily replaceable, focus only on the code and ignore everything else.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Never Reflecting or Asking the Hard Questions
&lt;/h2&gt;

&lt;p&gt;You cannot improve if you never pause to see where you are, where you want to go, and what you need to get there. Many developers go year after year without reflecting on what worked, what didn’t, and what they could do differently. Reflection is what turns experience into wisdom. Without it, you’re just moving in circles, accumulating years, but not skills.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fndrd211yug0dor9zi1p8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fndrd211yug0dor9zi1p8.png" alt="Reflect as a developer" width="800" height="499"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Reflection forces you to confront your blind spots, the bugs in your mindset and workflow that no tutorial can fix. It’s uncomfortable, but discomfort is where growth actually lives. So, that being said, if you want to flatline indefinitely, never reflect on your growth.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Growth is about thinking, creating, leading, and connecting. It’s about tackling uncomfortable challenges, building real projects, practicing consistently, communicating clearly, understanding the business, and taking ownership of your impact. Ignore any of these, and you’ll never move forward. Follow them, and even in a year, you’ll look back and be amazed at how far you’ve come. If you think coding harder alone will make you climb up the ranks? Think again.&lt;/p&gt;

&lt;p&gt;If you’ve made it this far, ask yourself: are you doing these things, or are you doing what’s easy? Because the difference between being a &lt;strong&gt;“developer”&lt;/strong&gt; and being a &lt;strong&gt;“developer who grows”&lt;/strong&gt; comes down to the choices you make every day.&lt;/p&gt;

</description>
      <category>softwareengineering</category>
      <category>careerdevelopment</category>
      <category>productivity</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to Survive AI as a Programmer</title>
      <dc:creator>Christian Mbah</dc:creator>
      <pubDate>Mon, 01 Sep 2025 10:11:37 +0000</pubDate>
      <link>https://dev.to/chrismbah/how-to-survive-ai-as-a-programmer-5hp</link>
      <guid>https://dev.to/chrismbah/how-to-survive-ai-as-a-programmer-5hp</guid>
      <description>&lt;p&gt;As a software engineer you've probably wondered at least once about the impact of &lt;strong&gt;Artificial Intelligence (AI)&lt;/strong&gt; on your long-term career.&lt;/p&gt;

&lt;p&gt;Everywhere you look, AI tools are popping up that can write code, fix bugs, and even generate an entire app from scratch in seconds. &lt;/p&gt;

&lt;p&gt;At first, it feels cool seeing how much artificial intelligence is growing and how much better it helps you solve coding tasks, but then the bigger question creeps in: if AI keeps getting better, will it eventually replace me in the long run?&lt;/p&gt;

&lt;h2&gt;
  
  
  Will AI replace software engineers?
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Well, yes and no.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;AI is already replacing some software engineers and that trend isn’t slowing down, but it &lt;strong&gt;won’t&lt;/strong&gt; replace all of us. That’s the part worth paying attention to and we’ll get into &lt;em&gt;why&lt;/em&gt; in a moment, but first let’s acknowledge the obvious: this shift isn’t shocking. &lt;/p&gt;

&lt;p&gt;As engineers, we’ve always built tools to replace old ways of working. This is just another wave of disruption, only now we’re the ones in the hot seat. Ironic, isn’t it? Building our own replacement.&lt;/p&gt;

&lt;p&gt;And if you think about it, this isn’t a new story. We build new things to improve or replace the old. Spotify reshaped the music industry, Netflix transformed how we watch movies, and Uber changed the way we think about taxis.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8suekdjfp5fiaoyhfqyo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8suekdjfp5fiaoyhfqyo.png" alt="Netflix, Uber and other main stream apps" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But here’s the good news: those older industries didn’t completely disappear. I still went to the cinema last week, taxi drivers migrated to Uber, and people still buy songs. The world changed, but it didn’t end, and the same will be true for software engineering.&lt;/p&gt;

&lt;p&gt;Which brings us to the real question: how do you survive, adapt, and stay valuable as a software engineer in the age of AI?&lt;/p&gt;

&lt;h2&gt;
  
  
  The Engineer Who Stands Out
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Fact: Artificial Intelligence can code like crazy.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You already know this so let's build on it. If AI can code, why not think beyond coding, broaden your perspective and use your technical skills together with knowledge from other fields to create real impact. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Let's take a case study of 2 software engineers:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Software Engineer 1:&lt;/strong&gt; Can code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Software Engineer 2:&lt;/strong&gt; Can code, but doesn't stop there. He's built range in multiple domains like product management, design, marketing, sales, or business strategy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ddm1x9waw5eom5ixgkf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ddm1x9waw5eom5ixgkf.png" alt="2 Software Engineers" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now picture this: both engineers are asked to build a feature for an e-commerce app.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Engineer 1&lt;/strong&gt; delivers clean, working code. The feature is technically solid, but that’s about it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Engineer 2&lt;/strong&gt; also writes the code, but because they understand product and user experience, they suggest a small tweak to improve checkout speed. Thanks to their grasp of business strategy, they highlight how this tweak could increase conversions. And with their communication skills, they explain the impact clearly to both the design and business teams.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both wrote code. But only one created impact. And that’s the engineer AI can’t easily replace.&lt;/p&gt;

&lt;p&gt;So if AI is already good at coding, which of these two engineers do you think will stand out in the long run? Exactly, the second one. The guy who connects technical skills with multiple domains and consistently drives outcomes that actually matter.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Edge Engineer 2 Has Over AI
&lt;/h2&gt;

&lt;p&gt;AI is insanely good at narrow, well-defined tasks. Ask it to optimize a query, generate boilerplate code, or refactor a function and it’ll crush it every time. But here’s the catch: AI doesn’t do well once you step outside of those boundaries. It can remix existing patterns, but it struggles to combine ideas from different domains to create something new.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Engineer 2’s&lt;/strong&gt; edge is exactly that: they don’t just code, they think. They pull from product, design, business, and even psychology to build things that actually matter. They understand customer pain points, connect dots across fields, and create value AI can’t see because it’s trained on the average of what’s &lt;em&gt;already been done&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqvvrgamo3svvlwrisuog.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqvvrgamo3svvlwrisuog.png" alt="Developer writing on a board" width="800" height="534"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The truth is, impact comes from &lt;em&gt;originality&lt;/em&gt; and &lt;em&gt;empathy&lt;/em&gt;, two areas where humans still have the upper hand. AI can code. &lt;strong&gt;Engineer 2&lt;/strong&gt; can create outcomes that change the game.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Become Engineer 2
&lt;/h2&gt;

&lt;p&gt;Becoming Engineer 2 means you stop being defined only by your ability to code and start stacking skills that make you indispensable. Here’s how:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Strengthen Your Core Technical Depth&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;AI can write code, but it doesn’t truly understand systems. Your technical foundation should be unshakable; architecture, scalability, debugging, and performance optimization are areas where depth matters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Learn to Think Like a Product Manager&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Understand why features are built, what problems they solve, and how they tie into business goals. Engineers who think beyond their tickets have a strategic edge.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Adopt Design Thinking&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You don’t need to be a designer, but knowing the principles of UX, UI, and user research will make your work far more impactful.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Understand Business and Growth&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Learn how companies make money, how products are sold, and what drives revenue. Engineers with business insight become trusted decision-makers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Invest in Soft Skills&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Communication, persuasion, and empathy are career multipliers. They determine how much influence you can have, no matter your technical strength.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Master AI Instead of Fearing It&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Learn how AI works, where it shines, and where it fails. Engineers who can use AI effectively will outperform those who ignore it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Collaborate Across Functions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Spend time with teams outside engineering like marketing, sales, design, operations. This is how you connect technical skill with real-world impact.&lt;/p&gt;

&lt;p&gt;Engineer 2’s advantage isn’t just their skills; it’s how they approach problems. The &lt;em&gt;multi-spired&lt;/em&gt; engineer doesn’t see themselves as “just a programmer”; they see themselves as a builder of value. And that mindset is what separates those who succeed in an AI-driven world from those who get left behind.&lt;/p&gt;

&lt;h2&gt;
  
  
  Having a Future-Proof Mindset
&lt;/h2&gt;

&lt;p&gt;The engineers who stay relevant in the age of AI aren’t the ones who cling to what they already know, they’re the ones who stay curious and adaptable. &lt;/p&gt;

&lt;p&gt;Curiosity is your edge. Keep exploring new tools, frameworks, and concepts, and never settle for just “doing your job.” Look past tickets and deadlines and learn the bigger picture: what your product does, who it serves, and why it matters.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsyl3ulimoy7e3woidbmg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsyl3ulimoy7e3woidbmg.png" alt="Curious developer" width="800" height="534"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The tech world will always shift, and those who grow with it will stay valuable. Sharpen your communication and leadership skills because engineers who can guide, influence, and connect ideas are rare. Stop seeing yourself as “just a programmer.” Start seeing yourself as a builder of real value.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Road Ahead
&lt;/h2&gt;

&lt;p&gt;AI will write more code than any single engineer ever could and there's nothing we can do about it. But code alone &lt;strong&gt;does not&lt;/strong&gt; create value. The software engineers who succeed will be the ones who decide what to build and why it matters.&lt;/p&gt;

&lt;p&gt;Don’t wait for layoffs or industry disruptions to force you into change. Start now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Learn a skill outside engineering.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Shadow a different team.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Take on a project that challenges you.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The future belongs to engineers who can see beyond the code. Stack your skills, connect the dots across disciplines, and become the person no tool can fully replace.&lt;/p&gt;

</description>
      <category>openai</category>
      <category>ai</category>
      <category>softwareengineering</category>
      <category>chatgpt</category>
    </item>
    <item>
      <title>Dev, Staging, and Production Environments in Software Development</title>
      <dc:creator>Christian Mbah</dc:creator>
      <pubDate>Sat, 23 Aug 2025 10:49:38 +0000</pubDate>
      <link>https://dev.to/chrismbah/dev-staging-and-production-environments-what-they-mean-in-software-development-90a</link>
      <guid>https://dev.to/chrismbah/dev-staging-and-production-environments-what-they-mean-in-software-development-90a</guid>
      <description>&lt;p&gt;Every software product always goes through multiple processes before it’s ready for real users. One of the most important of these processes is testing and validating the code in different environments.&lt;/p&gt;

&lt;p&gt;Instead of writing code on your computer and immediately releasing it to the world (which would be risky), software engineers use a structured flow: first &lt;strong&gt;development&lt;/strong&gt;, then &lt;strong&gt;staging&lt;/strong&gt;, and finally &lt;strong&gt;production&lt;/strong&gt;. Each of these environments serves a unique purpose, helping teams catch bugs that were missed, improve performance, and essentially ensures the final product is reliable for users.&lt;/p&gt;

&lt;p&gt;Think of it like you're a musician preparing for a big performance:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8w4liawne7fpnp8x8kyu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8w4liawne7fpnp8x8kyu.png" alt="Musician performing" width="612" height="387"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The development environment is where musicians practice individually&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1t4ejw3uwjzswqiihb39.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1t4ejw3uwjzswqiihb39.png" alt="Musician practicing" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The staging environment is the rehearsal with the whole band where they go through their performance and how good they sound together.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmeya8620so3kjj142f01.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmeya8620so3kjj142f01.png" alt="Band rehearal" width="800" height="532"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The production environment is the live concert, with the audience watching.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwugebm82s4w47vsa7p6f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwugebm82s4w47vsa7p6f.png" alt="Live concert of the musicians" width="512" height="512"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we've gotten all that cleared up, let's talk in detail about each of these stages, how they differ and how important each of them are in building a solid software product.&lt;/p&gt;

&lt;h2&gt;
  
  
  Development environment
&lt;/h2&gt;

&lt;p&gt;This is where all the building and experimenting happens and it's usually set up in your computer. It’s the space where your code is written and initially tested before it’s seen by anyone outside the team.&lt;/p&gt;

&lt;p&gt;Here, developers have the freedom to try out new features, fix bugs, or make changes without worrying about breaking the actual application that users depend on. It’s usually connected to a local database or dummy data so that testing doesn’t interfere with real information.&lt;/p&gt;

&lt;p&gt;The main players of this stage are the &lt;strong&gt;software developers&lt;/strong&gt; themselves.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F48xm4po0l54pcsd52xao.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F48xm4po0l54pcsd52xao.png" alt="Software engineers" width="800" height="453"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Staging environment
&lt;/h2&gt;

&lt;p&gt;Once you’ve got your code working in development, the next stop is the staging environment and you can think of this as your _“final rehearsal” _ before going live.&lt;/p&gt;

&lt;p&gt;In staging, your app runs on a server that’s set up to be as close as possible to production. This means it uses almost the same configuration, services, and dependencies that your real users will eventually rely on but since it’s still a safe space, if something breaks here, it won’t affect actual customers.&lt;/p&gt;

&lt;p&gt;The main players of this stage are the &lt;strong&gt;Quality Assurance (QA) testers&lt;/strong&gt;. They’re the ones stress-testing your work, hunting bugs, and making sure it’s polished before it goes live (sometimes a bit of a headache for us developers 😅)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi1d0gw6ugfp2x0j002vj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi1d0gw6ugfp2x0j002vj.png" alt="QA tester" width="788" height="443"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Production environment
&lt;/h2&gt;

&lt;p&gt;This is it, the main event. In this environment, your app finally goes live and real users interact with it. Everything that happens here matters because it’s tied to actual customers, real data, and in many cases, real money.&lt;/p&gt;

&lt;p&gt;Unlike development or staging, production isn’t very forgiving. If something breaks here, your users will notice, and that can mean frustrated customers, lost revenue, or even security issues. That’s why teams are extra careful about what gets deployed into production.&lt;/p&gt;

&lt;p&gt;In this environment, you’ll see practices like &lt;strong&gt;gradual rollouts&lt;/strong&gt; (where updates are released to a small group of users first), &lt;strong&gt;blue-green deployments&lt;/strong&gt;, or &lt;strong&gt;canary releases&lt;/strong&gt;. These strategies let you push updates with less risk, so if something goes wrong, you can roll it back before too many people are affected.&lt;/p&gt;

&lt;p&gt;Monitoring and security are also a huge deal here. You’ll want logging, alerts, and backup systems in place so you can react quickly if there’s ever a problem.&lt;/p&gt;

&lt;p&gt;The main players are the &lt;strong&gt;users&lt;/strong&gt; themselves. At this stage, it’s no longer about the developer or QA but giving your users the smoothest, most reliable experience possible.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fha4ou4c167egwjqo4wgm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fha4ou4c167egwjqo4wgm.png" alt="Users making use of an app" width="800" height="544"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;So, to sum it all up:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Development&lt;/strong&gt; is your playground where you build, test, and break things.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Staging&lt;/strong&gt; is your dress rehearsal; the space to polish, demo, and catch problems before going live.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Production&lt;/strong&gt; is the big show, where your users are watching, and everything needs to run smoothly.&lt;/p&gt;

&lt;p&gt;Understanding these environments isn’t just for developers. It also helps product managers, designers, and even stakeholders appreciate the path from idea to a reliable product in users’ hands. At the end of the day, it's what keeps your software reliable, your team sane, and your users happy. &lt;/p&gt;

</description>
      <category>softwaredevelopment</category>
      <category>softwareengineering</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>What's the Difference between NPM and NPX</title>
      <dc:creator>Christian Mbah</dc:creator>
      <pubDate>Sat, 24 May 2025 17:22:21 +0000</pubDate>
      <link>https://dev.to/chrismbah/whats-the-difference-between-npm-and-npx-2eim</link>
      <guid>https://dev.to/chrismbah/whats-the-difference-between-npm-and-npx-2eim</guid>
      <description>&lt;p&gt;Every developer working with JavaScript has likely used one or both of these tools: &lt;strong&gt;NPM&lt;/strong&gt; and &lt;strong&gt;NPX&lt;/strong&gt;. But while they’re often used together, they serve very different purposes, and that can be confusing, especially for beginners. In fact, many developers use them without fully understanding what each one does or why they're using it.&lt;/p&gt;

&lt;p&gt;Let’s break it down in the simplest way possible.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is NPM?
&lt;/h2&gt;

&lt;p&gt;NPM stands for &lt;strong&gt;Node Package Manager&lt;/strong&gt;. It’s the default package manager for Node.js mainly used for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Installing packages (libraries, tools, etc.) into your project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Managing and updating dependencies in your &lt;code&gt;package.json&lt;/code&gt; file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Running scripts defined in &lt;code&gt;package.json&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;react
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command installs React and adds it to your &lt;code&gt;node_modules&lt;/code&gt; folder and &lt;code&gt;package.json&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is NPX?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;NPX&lt;/strong&gt; stands for &lt;strong&gt;Node Package eXecute&lt;/strong&gt;. It’s a tool that lets you run any package directly from the NPM registry, without needing to install it globally or keep it in your project.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-react-app my-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This runs the create-react-app command without requiring a global install. It temporarily downloads and executes it, then cleans up after itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  When to Use NPM vs NPX
&lt;/h2&gt;

&lt;p&gt;Use &lt;strong&gt;NPM&lt;/strong&gt; when you want to add a package to your project and manage it over time.&lt;/p&gt;

&lt;p&gt;Use &lt;strong&gt;NPX&lt;/strong&gt; when you want to run a tool or command temporarily, like a one-time script.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Does It Matter?
&lt;/h2&gt;

&lt;p&gt;Knowing the difference helps you avoid cluttering your system with global installs and keeps your development environment cleaner.&lt;/p&gt;

&lt;p&gt;So if you're not sure whether to use npm or npx, ask yourself:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Do I need this tool installed in my project permanently?&lt;/li&gt;
&lt;li&gt;If yes, use npm.&lt;/li&gt;
&lt;li&gt;If no, or just for a quick command, use npx.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>npm</category>
      <category>npx</category>
    </item>
    <item>
      <title>What Does Simple Addition Look Like in 10 Programming Languages?</title>
      <dc:creator>Christian Mbah</dc:creator>
      <pubDate>Sat, 10 May 2025 10:27:10 +0000</pubDate>
      <link>https://dev.to/chrismbah/what-does-simple-addition-look-like-in-10-programming-languages-2ed2</link>
      <guid>https://dev.to/chrismbah/what-does-simple-addition-look-like-in-10-programming-languages-2ed2</guid>
      <description>&lt;p&gt;When starting with a new programming language—whether through tutorials or courses—one of the first tasks we do is usually performing a basic calculation. It’s a simple but effective way to get familiar with the syntax and language rules.&lt;/p&gt;

&lt;p&gt;I got curious and decided to see how different languages handle basic calculation. Here, I’ll perform the simple addition operation “5 + 3” in 10 different programming languages, and the goal here is to explore how each language syntax differs in readability. I'll also note their compile and/or runtime and provide a rating out of 10 based on the readability of their syntax as well as list them in descending order.&lt;/p&gt;

&lt;p&gt;For consistency, I used the online coding platform &lt;a href="https://jdoodle.com" rel="noopener noreferrer"&gt;&lt;strong&gt;JDoodle&lt;/strong&gt;&lt;/a&gt;, so you can easily try out the examples yourself. Please note that the runtime is based on the JDoodle environment and doesn’t necessarily reflect how fast each language would run in a native or optimized environment. It just serves as a way to compare the languages in a controlled setup.&lt;/p&gt;

&lt;p&gt;Now that’s all cleared up, let's begin!&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Python
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;

&lt;span class="nf"&gt;print &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;sum of x+y =&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Python makes it so easy: assign the values in variables &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt;⁣, store the added values in variable ⁣&lt;code&gt;z&lt;/code&gt; and use the &lt;code&gt;print()&lt;/code&gt; function to display the result. It doesn’t get easier than this. Clean, simple, and easy to read.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Runtime:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;0.902 sec(s)&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Rating:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;9.5&lt;/p&gt;

&lt;p&gt;To the surprise of no one, Python is at the top of the list. It’s simplicity and readability make it an ideal choice for beginners; it allows them to focus on learning without being overwhelmed by complex syntax.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: Some runtimes show "N/A" because of limitations in JDoodle's runtime environment.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;2. JavaScript&lt;/strong&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JavaScript &lt;code&gt;console.log&lt;/code&gt; does the job here. It uses the &lt;code&gt;let&lt;/code&gt; keyword in assigning variables, stores the added value in a variable, and simply prints it out in the browser’s console. It’s simple, easy to read, versatile, and very useful for debugging.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Runtime&lt;/strong&gt;:
&lt;/h3&gt;

&lt;p&gt;N/A&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Rating&lt;/strong&gt;:
&lt;/h3&gt;

&lt;p&gt;9.0&lt;/p&gt;

&lt;p&gt;It's syntax is clean and straightforward, making it a popular choice for both beginners and experienced developers.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. C
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt;&lt;span class="cpf"&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Sum of x+y = %i"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;C requires a bit more setup compared to Python and JavaScript, but that’s what makes learning low-level languages important. It helps you understand the mechanics of memory management and how operations work at a deeper level.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Runtime:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;1.132 sec(s)&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Rating:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;8.0/10&lt;/p&gt;

&lt;p&gt;C provides more control over system resources but requires more boilerplate code, making it less beginner-friendly for simple tasks like addition.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. PHP
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

    &lt;span class="nv"&gt;$x&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;$y&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;$z&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$x&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nv"&gt;$y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nv"&gt;$msg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Sum of x+y = '&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$msg&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;$z&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;PHP is a widely used scripting language designed for web development. It’s simple, user-friendly, and readable, especially when dealing with basic operations. While PHP may not be as fast or strict as some compiled languages, it's great for web scripting and server-side applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Runtime:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;N/A&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Rating:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;7.5/10&lt;/p&gt;

&lt;p&gt;The syntax is simple and straightforward but could be more structured and robust for larger, more complex applications&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Go
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;
    &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;
    &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;

    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Sum of x + y = %d"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go’s syntax is very straightforward and is designed for efficiency and scalability, especially in concurrent programming.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Runtime:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;N/A&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Rating:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;7.0/10&lt;/p&gt;

&lt;p&gt;Although the syntax is simple and effective for concurrent and scalable programming, the extra imports and verbosity for output reduce its overall simplicity compared to the previous languages.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. C++
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;iostream&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="k"&gt;namespace&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;cout&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s"&gt;"Sum of x+y = "&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;C++ syntax is relatively clear, but it requires more boilerplate than languages like Python or JavaScript. The need for header files and the use of &lt;code&gt;cout&lt;/code&gt; for output might make the code feel a bit more complex, though it allows for greater control over performance and memory management.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Runtime:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;1.052 sec(s)&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Rating:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;6.8/10&lt;/p&gt;

&lt;p&gt;The syntax is straightforward but adds verbosity with its use of header files and manual output handling. While powerful, it may feel complex for beginners looking for quick and simple calculations.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. C
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;System&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Program&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Sum of x + y = "&lt;/span&gt;&lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;C# follows a structured approach, but the need for defining a class and using specific methods such as &lt;code&gt;Console.Write&lt;/code&gt; makes it more verbose compared to higher-level languages. The syntax is clear, but it’s less beginner-friendly and involves more boilerplate code for a simple task.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Runtime:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;12.075 sec(s)&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Rating:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;6.5/10&lt;/p&gt;

&lt;p&gt;Although the code is easy to read, it introduces more complexity due to the necessity of class structures and method calls. The added boilerplate reduces the efficiency for a simple calculation.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Java
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyClass&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;[])&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Java requires defining a full class structure, which feels excessive for a simple calculation. Its strict syntax ensures reliability and performance but adds complexity, making it less intuitive for beginners.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Runtime:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;1.402 sec(s)&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Rating:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;6.0/10&lt;/p&gt;

&lt;p&gt;The need for a class structure and the strict syntax makes Java feel cumbersome for a simple task like addition, although it’s powerful and efficient once you get familiar.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. Objective-C
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight objective_c"&gt;&lt;code&gt;&lt;span class="cp"&gt;#import &amp;lt;Foundation/Foundation.h&amp;gt;
&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;argc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[])&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;NSAutoreleasePool&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;pool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="n"&gt;NSAutoreleasePool&lt;/span&gt; &lt;span class="nf"&gt;alloc&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;NSLog&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;@"Sum of x + y = %i"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;pool&lt;/span&gt; &lt;span class="nf"&gt;drain&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Objective-C adds object-oriented features to C, but the syntax is much more verbose, especially for simple tasks like addition. It’s powerful but requires more boilerplate code that isn’t easily readable, making it less beginner-friendly compared to other languages like C++ or even Java.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Runtime:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;7.846 sec(s)&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Rating:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;5.5/10&lt;/p&gt;

&lt;p&gt;The verbose syntax and additional boilerplate make it harder to write and understand for simple tasks, though it is still powerful and flexible for complex applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. Assembly
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;section .text

global _start

_start:

    mov     eax, [x]
    sub     eax, '0'
    mov     ebx, [y]
    sub     ebx, '0'
    add     eax, ebx
    add     eax, '0'

    mov     [sum], eax

    mov     ecx, msg
    mov     edx, len
    mov     ebx, 1
    mov     eax, 4
    int     0x80

    mov     ecx, sum
    mov     edx, 1
    mov     ebx, 1
    mov     eax, 4
    int     0x80

    mov     eax, 1
    int     0x80

section .data
    x db '5'
    y db '3'
    msg db  "sum of x and y is "
    len equ $ - msg

segment .bss

    sum resb 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Assembly language is extremely low-level and requires extensive code even for simple operations like addition. Although it offers maximum control over system hardware and performance, the complexity and verbosity make it unsuitable for simple tasks and less beginner-friendly than higher-level languages.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Runtime:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;0.876 sec(s)&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Rating:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;4.0/10&lt;/p&gt;

&lt;p&gt;It’s no surprise that this gets last place. It’s too verbose, prone to errors, and &lt;em&gt;definitely&lt;/em&gt; not practical for simple tasks.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Reflection&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I find it interesting how something as simple as adding two numbers can be expressed in so many different ways. But one thing that’s certain is that although each language has its own unique syntax and rules, they all ultimately achieve the same result. Some languages may have simpler syntax, while others are more complex, but at the end of the day, each of them has their strengths and weaknesses, and they’re all just tools for solving problems.&lt;/p&gt;

&lt;p&gt;So which of these languages do you prefer for simple tasks? Feel free to share your thoughts!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>python</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How to Build a simple REST API with Node, Express and MongoDB</title>
      <dc:creator>Christian Mbah</dc:creator>
      <pubDate>Fri, 09 May 2025 11:30:49 +0000</pubDate>
      <link>https://dev.to/chrismbah/how-to-build-a-simple-rest-api-with-node-express-and-mongodb-2d4n</link>
      <guid>https://dev.to/chrismbah/how-to-build-a-simple-rest-api-with-node-express-and-mongodb-2d4n</guid>
      <description>&lt;p&gt;&lt;strong&gt;APIs&lt;/strong&gt; have always been an important component of modern technology. Whenever we interact with a computer or system to retrieve information or perform a function, Application Programming Interfaces &lt;strong&gt;(APIs)&lt;/strong&gt; are what help us communicate what we want to the system so it can understand and fulfill those requests. Among these, &lt;strong&gt;REST APIs&lt;/strong&gt; are a popular choice because they are simple to use and can handle a lot of different tasks.&lt;/p&gt;

&lt;p&gt;In this article we will be building a simple &lt;strong&gt;todo list&lt;/strong&gt; REST API for managing tasks using Express and MongoDB. You’ll cover everything from setting up your project to building the endpoints that handle CRUD (Create, Read, Update, Delete) operations, and by the end you’ll have the foundational skills to create your own APIs with Express and MongoDB.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before you begin, ensure you have:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Node.js Installed:&lt;/strong&gt; Make sure Node.js is installed on your computer. You can download it from &lt;a href="https://nodejs.org" rel="noopener noreferrer"&gt;nodejs.org&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;MongoDB Setup:&lt;/strong&gt; Either install MongoDB locally and access it with the GUI &lt;a href="https://www.mongodb.com/products/compass" rel="noopener noreferrer"&gt;MongoDB Compass&lt;/a&gt; or create a free account on &lt;a href="https://www.mongodb.com/cloud/atlas" rel="noopener noreferrer"&gt;MongoDB Atlas&lt;/a&gt; for a cloud-based database.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;API Testing Tool:&lt;/strong&gt; Install &lt;strong&gt;Postman&lt;/strong&gt;, &lt;strong&gt;Insomnia,&lt;/strong&gt; or &lt;strong&gt;Thunder Client&lt;/strong&gt; to test the endpoints.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Setting Up Your Project
&lt;/h2&gt;

&lt;p&gt;Start by creating a folder with any name you like. For this guide, I’ll advise you to use &lt;code&gt;rest-api&lt;/code&gt; to keep things consistent. After that, open it in your preferred IDE. If you’re unsure, &lt;strong&gt;Visual Studio Code&lt;/strong&gt; is a great choice.&lt;/p&gt;

&lt;p&gt;Open the terminal in your VS Code or any IDE of your choice, navigate to the folder, and run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm init &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a &lt;code&gt;package.json&lt;/code&gt; file with default settings to manage your project dependencies.&lt;/p&gt;

&lt;p&gt;Next, install the following packages by running the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;express mongoose nodemon dotenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’ll be making use of the packages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;express&lt;/strong&gt;: For building the server.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;mongoose&lt;/strong&gt;: To interact with MongoDB.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;nodemon&lt;/strong&gt;: For automatically restarting the server during development.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;dotenv:&lt;/strong&gt; To manage environment variables securely.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To make development easier and prevent manually restarting the server after every change, add a &lt;code&gt;start&lt;/code&gt; script in your &lt;code&gt;package.json&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; 
    &lt;/span&gt;&lt;span class="nl"&gt;"start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"nodemon index.js"&lt;/span&gt;&lt;span class="w"&gt; 
 &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This allows you to start your server with the command &lt;code&gt;npm start&lt;/code&gt; . Your &lt;code&gt;package.json&lt;/code&gt; file should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"rest-api"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1.0.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"main"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"index.js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"test"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"echo &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;Error: no test specified&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt; &amp;amp;&amp;amp; exit 1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"nodemon index.js"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"keywords"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"author"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"license"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ISC"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"dependencies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"dotenv"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^16.4.7"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"express"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^4.21.2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"mongoose"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^8.9.4"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"nodemon"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^3.1.9"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Connecting to MongoDB&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Now that your project is all set up, the next step is to connect to your database, MongoDB.&lt;/p&gt;

&lt;p&gt;Start by creating a &lt;code&gt;.env&lt;/code&gt; file at the root of your folder. This is where you’ll store your MongoDB connection URI. This way, you can keep credentials safe and easily configurable.&lt;/p&gt;

&lt;p&gt;Inside the &lt;code&gt;.env&lt;/code&gt; file, store your connection URI in a variable, like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;MONGO_URI&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;your_mongodb_connection_string
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are using &lt;strong&gt;MongoDB Atlas&lt;/strong&gt;, you can get the connection string from your Atlas dashboard. For local MongoDB with &lt;strong&gt;MongoDB Compass&lt;/strong&gt;, it might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;MONGO_URI&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;mongodb://localhost:27017/rest-api
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, create a new file at the root of your project called &lt;code&gt;db.js&lt;/code&gt; to manage the MongoDB connection.&lt;/p&gt;

&lt;p&gt;Inside &lt;code&gt;db.js&lt;/code&gt;, add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// db.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mongoose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mongoose&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dotenv&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;config&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Load environment variables&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;connectDB&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;mongoose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;MONGO_URI&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;MongoDB connected&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Catch error if connection fails&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Error connecting to MongoDB:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;connectDB&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a simple function for connecting your server to MongoDB with your connection URI.&lt;/p&gt;

&lt;p&gt;Now create a &lt;code&gt;index.js&lt;/code&gt; file that would be your main file. Then require and invoke the &lt;code&gt;connectDB&lt;/code&gt; function to establish a connection to your database.&lt;/p&gt;

&lt;p&gt;Example &lt;code&gt;index.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// index.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;connectDB&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./db&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nf"&gt;connectDB&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Connect to database&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Middleware to parse JSON requests&lt;/span&gt;

&lt;span class="c1"&gt;// Define a simple route&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello World!!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;PORT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PORT&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;PORT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Server running on port &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;PORT&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the server with the command &lt;code&gt;npm run start&lt;/code&gt; in your terminal. If everything is set up correctly, you should see the message &lt;code&gt;MongoDB connected&lt;/code&gt; in the terminal.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgahjl0ief4wznkyxgkwq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgahjl0ief4wznkyxgkwq.png" alt="npm run start" width="416" height="136"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well, congratulations! You just started your node server.&lt;/p&gt;

&lt;h2&gt;
  
  
  Defining the data model
&lt;/h2&gt;

&lt;p&gt;The next step is to create a &lt;strong&gt;model&lt;/strong&gt; to define the structure of the data stored in MongoDB. For this tutorial, you’ll create a model for managing a collection of "tasks" in the to-do app.&lt;/p&gt;

&lt;p&gt;Inside your project create a &lt;code&gt;models&lt;/code&gt; folder to keep your models organized. Inside the &lt;code&gt;models&lt;/code&gt; folder, create a &lt;code&gt;Task.js&lt;/code&gt; file to define the schema.&lt;/p&gt;

&lt;h2&gt;
  
  
  Define the Task Schema
&lt;/h2&gt;

&lt;p&gt;To define the model of each task, add the following code to &lt;code&gt;Task.js&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mongoose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mongoose&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Define the Task schema&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;TaskSchema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;mongoose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Schema&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Title is required&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;completed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Create and export the Task model&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Task&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mongoose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Task&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;TaskSchema&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Explaining the schema fields
&lt;/h2&gt;

&lt;p&gt;To keep things simple, you’ll be using just a few fields in your schema, with each field having:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;title&lt;/strong&gt;: A required string field to store the task's title.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;description&lt;/strong&gt;: An optional string field to store additional details about the task.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;completed&lt;/strong&gt;: A boolean field indicating whether the task is done. By default, it’s set to &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With this schema defined, you can now use the &lt;code&gt;Task&lt;/code&gt; model to interact with the &lt;code&gt;tasks&lt;/code&gt; collection in MongoDB.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Building the API Endpoints&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The next step is to &lt;strong&gt;create API endpoints&lt;/strong&gt; for handling CRUD operations in the todo app. These endpoints will allow you to interact with the &lt;code&gt;tasks&lt;/code&gt; collection in MongoDB through requests.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up routers
&lt;/h2&gt;

&lt;p&gt;The first step is to set up routers, which creates the routes that define endpoints. Create a folder named &lt;code&gt;routes&lt;/code&gt; and a file named &lt;code&gt;task.js&lt;/code&gt; inside it. Add the following code to your&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// routes/task.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Task&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../models/Task&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Import the Task schema&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;router&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Initialize the router&lt;/span&gt;

&lt;span class="c1"&gt;// Endpoints goes here&lt;/span&gt;

&lt;span class="c1"&gt;// Export the router for use in other files&lt;/span&gt;
&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The next step is to make your requests with the router.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a Task
&lt;/h2&gt;

&lt;p&gt;Creating a task is done using a &lt;strong&gt;POST request&lt;/strong&gt;, which is typically used to send data to the server to create a new resource.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Creating a new task&lt;/span&gt;
&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;task&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;201&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;task&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here’s a quick explanation of the code:&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;router.post('/', ...)&lt;/code&gt; function that handles the &lt;code&gt;POST&lt;/code&gt; request sent to &lt;code&gt;/api/tasks&lt;/code&gt; You used &lt;code&gt;/&lt;/code&gt; here because the router will be mounted under &lt;code&gt;/api/tasks&lt;/code&gt; in the main app file.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;new Task(req.body)&lt;/code&gt; creates a new task instance using the data from the request’s body and &lt;code&gt;task.save()&lt;/code&gt; saves the task to the tasks collection in your database.&lt;/p&gt;

&lt;p&gt;If successful, the server responds with a status code &lt;code&gt;201&lt;/code&gt; (Created) and the saved task data, but if there’s an error, a &lt;code&gt;500&lt;/code&gt; status code is sent with an error message.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fetching Tasks
&lt;/h2&gt;

&lt;p&gt;The next endpoint you’ll implement allows the client to fetch a list of all tasks stored in the database. This is done using a &lt;strong&gt;GET request&lt;/strong&gt;, which is typically used to fetch data from the server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Get all tasks&lt;/span&gt;
&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;tasks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Fetch all tasks from the database&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;tasks&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt; &lt;span class="c1"&gt;// Return the list of tasks&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To retrieve tasks, the &lt;code&gt;router.get('/', ...)&lt;/code&gt; function is used to handle &lt;strong&gt;GET requests&lt;/strong&gt; sent to &lt;code&gt;/api/tasks&lt;/code&gt;. This endpoint will fetch all tasks from the database using the &lt;code&gt;Task.find()&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;Once all the tasks are retrieved, the server responds with a status code &lt;code&gt;200&lt;/code&gt; and sends the tasks in JSON format. If an error occurs during this process, the server responds with a &lt;code&gt;500&lt;/code&gt; status code and an error message to help diagnose the problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  Updating a Task
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;PUT&lt;/strong&gt; request allows you to update an existing task in the database. You’ll handle this by using the task's &lt;code&gt;ID&lt;/code&gt;⁣ to locate it, and then you’ll update the fields that are passed in the request.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Update a task&lt;/span&gt;
&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/:id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;description&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;completed&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Extract the task ID from the URL&lt;/span&gt;

    &lt;span class="c1"&gt;// Find the task by ID and update it&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;updatedTask&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findByIdAndUpdate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;description&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;completed&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;new&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="c1"&gt;// Return the updated task&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// If no task is found, return an error&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;updatedTask&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Task not found&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="c1"&gt;// Respond with the updated task&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;updatedTask&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the &lt;code&gt;router.put('/:id', ...)&lt;/code&gt; function handles &lt;strong&gt;PUT requests&lt;/strong&gt; sent to &lt;code&gt;/api/tasks/:id&lt;/code&gt;, where &lt;code&gt;:id&lt;/code&gt; is a placeholder for the task’s unique identifier. This endpoint is responsible for updating an existing task with the specified ID.&lt;/p&gt;

&lt;p&gt;The new task data is extracted from &lt;code&gt;req.body&lt;/code&gt;, while &lt;code&gt;req.params.id&lt;/code&gt; contains the ID of the task to be updated. Using &lt;code&gt;Task.findByIdAndUpdate(id, updateData, options)&lt;/code&gt;, the task is located and updated with the provided data. The &lt;code&gt;{ new: true }&lt;/code&gt; option ensures that the updated task is returned in the response.&lt;/p&gt;

&lt;p&gt;If the task with the specified ID isn’t found, the server responds with a &lt;code&gt;404&lt;/code&gt; status and a message indicating that the task doesn’t exist. For any other errors, a &lt;code&gt;500&lt;/code&gt; status is sent along with the error message to help debug the issue.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deleting a Task
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;DELETE&lt;/strong&gt; request allows you to delete a specific task from the database using its &lt;code&gt;ID&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Delete a task&lt;/span&gt;
&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/:id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Extract the task ID from the URL&lt;/span&gt;
    &lt;span class="c1"&gt;// Find and delete the task by ID&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;deletedTask&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findByIdAndDelete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// If no task is found, return an error message&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;deletedTask&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Task not found&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Task deleted successfully&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;router.delete('/:id', ...)&lt;/code&gt; function handles &lt;strong&gt;DELETE requests&lt;/strong&gt; sent to &lt;code&gt;/api/tasks/:id&lt;/code&gt;, where &lt;code&gt;:id&lt;/code&gt; represents the unique identifier of the task to be deleted. This endpoint is designed to remove a specific task from the database.&lt;/p&gt;

&lt;p&gt;The task ID is extracted from the URL using &lt;code&gt;req.params.id&lt;/code&gt;. The &lt;code&gt;Task.findByIdAndDelete(id)&lt;/code&gt; method is then used to find and delete the task with the specified ID. If the task doesn’t exist, the server responds with a &lt;code&gt;404&lt;/code&gt; status and a message indicating that the task couldn’t be found.&lt;/p&gt;

&lt;p&gt;After the task has been deleted, the server returns a &lt;code&gt;200&lt;/code&gt; status along with a success message. In case of any errors during this process, the server catches the error and responds with a &lt;code&gt;500&lt;/code&gt; status and the corresponding message.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;In summary, your &lt;code&gt;routes/tasks.js&lt;/code&gt; file should finally look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// routes/task.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Task&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../models/Task&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Import the Task schema&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;router&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Initialize the router&lt;/span&gt;

&lt;span class="c1"&gt;// Creating a new task&lt;/span&gt;
&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;task&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;201&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;task&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Get all tasks&lt;/span&gt;
&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;tasks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Fetch all tasks from the database&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;tasks&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt; &lt;span class="c1"&gt;// Return the list of tasks&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Update a task&lt;/span&gt;
&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/:id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;description&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;completed&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Extract the task ID from the URL&lt;/span&gt;

    &lt;span class="c1"&gt;// Find the task by ID and update it&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;updatedTask&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findByIdAndUpdate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;description&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;completed&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;new&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="c1"&gt;// Return the updated task&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// If no task is found, return an error&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;updatedTask&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Task not found&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="c1"&gt;// Respond with the updated task&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;updatedTask&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Delete a task&lt;/span&gt;
&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/:id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Extract the task ID from the URL&lt;/span&gt;
    &lt;span class="c1"&gt;// Find and delete the task by ID&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;deletedTask&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findByIdAndDelete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// If no task is found, return an error message&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;deletedTask&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Task not found&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Task deleted successfully&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Export the router for use in other files&lt;/span&gt;
&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Don’t forget to call your router in your &lt;code&gt;index.js&lt;/code&gt; file after creating the endpoints&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// index.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;tasksRouter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./routes/tasks&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Using the tasks router&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/tasks&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;tasksRouter&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, your folder structure should look a lot like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffwbt49xo3f0chle8p4ov.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffwbt49xo3f0chle8p4ov.png" alt="File structure" width="273" height="452"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing the Endpoints
&lt;/h2&gt;

&lt;p&gt;You can use tools like &lt;strong&gt;Postman&lt;/strong&gt;, &lt;strong&gt;Thunder Client&lt;/strong&gt;, or any API testing tool to test the endpoints.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1. Creating a Task&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;HTTP Method&lt;/strong&gt;: &lt;code&gt;POST&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;URL&lt;/strong&gt;: &lt;code&gt;http://localhost:5000/api/tasks&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Body&lt;/strong&gt;: Add a JSON body with the task data:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Buy groceries"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Milk, bread, and eggs"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"completed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Expected Result&lt;/strong&gt;: The response should include the newly created task with a status code of &lt;code&gt;201&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;2. Get All Tasks&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;HTTP Method&lt;/strong&gt;: &lt;code&gt;GET&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;URL&lt;/strong&gt;: &lt;code&gt;http://localhost:5000/api/tasks&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Expected Result&lt;/strong&gt;: The response should include a list of all tasks. If there are no tasks, you’ll see an empty array (&lt;code&gt;[]&lt;/code&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;3. Update a Task&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;HTTP Method&lt;/strong&gt;: &lt;code&gt;PUT&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;URL&lt;/strong&gt;: &lt;code&gt;http://localhost:5000/api/tasks/:id&lt;/code&gt;&lt;br&gt;&lt;br&gt;
&lt;em&gt;(Replace&lt;/em&gt; &lt;code&gt;:id&lt;/code&gt; with the actual ID of the task you want to update.)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Body&lt;/strong&gt;: Add the updated task data in the JSON format:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Updated Task Title"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Updated task description"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"completed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Expected Result&lt;/strong&gt;: The response should include the updated task with a status code of &lt;code&gt;200&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;4. Delete a Task&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;HTTP Method&lt;/strong&gt;: &lt;code&gt;DELETE&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;URL&lt;/strong&gt;: &lt;code&gt;http://localhost:5000/api/tasks/:id&lt;/code&gt;&lt;br&gt;&lt;br&gt;
&lt;em&gt;(Replace&lt;/em&gt; &lt;code&gt;:id&lt;/code&gt; with the actual ID of the task you want to delete.)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Expected Result&lt;/strong&gt;: A confirmation message such as:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Task deleted successfully"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These tests make sure that your endpoints are functioning as expected. If any test fails, check your code for errors, validate the data, and ensure your server and MongoDB are running correctly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Finalizing the Project
&lt;/h2&gt;

&lt;p&gt;To prepare your project to be scalable and maintainable, it’s best to structure it into distinct folders such as &lt;code&gt;routes/&lt;/code&gt;⁣, &lt;code&gt;models/&lt;/code&gt; and &lt;code&gt;config/&lt;/code&gt;⁣. Also make sure you store sensitive information like the database URI and API keys in a &lt;code&gt;.env&lt;/code&gt; file and use the &lt;code&gt;dotenv&lt;/code&gt; package to access them in your code.&lt;/p&gt;

&lt;p&gt;For deployment, you can host your server on platforms like &lt;a href="https://www.heroku.com/" rel="noopener noreferrer"&gt;Heroku&lt;/a&gt; and &lt;a href="https://vercel.com/" rel="noopener noreferrer"&gt;Vercel&lt;/a&gt;. Both platforms offer free tiers, making it easy to deploy your REST API.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;To sum it up:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You learned how to create a simple REST API using Express and MongoDB, implementing the fundamental CRUD operations (Create, Read, Update, Delete).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You also saw how to set up and structure your project to keep it clean and scalable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You’ve also tested your API with Postman or Thunder Client.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With this, you can now start building your own REST APIs and even expand it further by adding more features, such as authentication or proper data validation when making requests.&lt;/p&gt;

</description>
      <category>node</category>
      <category>express</category>
      <category>mongodb</category>
      <category>webdev</category>
    </item>
    <item>
      <title>6 Best Practices in Software Engineering</title>
      <dc:creator>Christian Mbah</dc:creator>
      <pubDate>Thu, 08 May 2025 08:53:42 +0000</pubDate>
      <link>https://dev.to/chrismbah/6-best-practices-in-software-engineering-2io6</link>
      <guid>https://dev.to/chrismbah/6-best-practices-in-software-engineering-2io6</guid>
      <description>&lt;p&gt;Best practices are a &lt;strong&gt;set of guidelines, ethics, or ideas&lt;/strong&gt; that represent the most effective or safest method of achieving a business function. It is a method or technique that has been broadly accepted as superior to others in its category due to the fact that it has a tendency to produce superior results.&lt;/p&gt;

&lt;h2&gt;
  
  
  Best Practices in Software Engineering
&lt;/h2&gt;

&lt;p&gt;Best practices in software engineering are established guidelines and principles that help teams create high-quality, maintainable, and effective software products with fewer errors and rework. They offer a template for organizing workflows, improving collaboration, and delivering reliable software that meets user and business needs.&lt;/p&gt;

&lt;p&gt;The importance of best practices in software engineering is in their ability to improve code quality, reduce bugs, improve security, and save time and costs over the project lifecycle. I’ve created a list of best practices every software engineer should adhere to, and by following these practices, teams can create adaptable and scalable software that remains relevant amid changing technologies and requirements.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. DRY principle
&lt;/h2&gt;

&lt;p&gt;The DRY principle — "Don't Repeat Yourself" — is simply not being redundant in your code. Instead of duplicating logic in multiple places throughout your codebase, you want to write reusable components: functions, classes, or modules that can be reused wherever they are needed.&lt;/p&gt;

&lt;p&gt;By avoiding duplication, you reduce &lt;a href="https://en.wikipedia.org/wiki/Technical_debt" rel="noopener noreferrer"&gt;technical debt&lt;/a&gt; and the risk of inconsistencies or bugs when you must make modifications. When an item of logic needs changing, you only have to modify it in one place — and the improvement is reflected wherever it's used. The outcome is cleaner and more organized code that's easier to read, test, and debug.&lt;/p&gt;

&lt;p&gt;DRY can be achieved through &lt;strong&gt;abstraction&lt;/strong&gt; — identifying repeated patterns and turning them into reusable building blocks. When applied consistently, it speeds up development, promotes consistency, and makes it easier for teams to collaborate, since the codebase becomes more organized and predictable.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. KISS principle
&lt;/h2&gt;

&lt;p&gt;This stands for “Keep It Simple, Stupid” and it emphasizes simplicity in design and code, avoiding over-engineering, and focusing on clear, maintainable, and efficient solutions. In software engineering, it’s easy to overthink a solution — adding multiple layers of logic, edge case handling, and abstractions that aren’t immediately needed. While it might feel like you’re future-proofing your code, most times you’re just making it harder to understand, test, and maintain.&lt;/p&gt;

&lt;p&gt;Keeping things simple means solving the problem at hand with the &lt;strong&gt;most straightforward, readable solution possible&lt;/strong&gt;. It doesn’t mean ignoring edge cases or scalability, but rather handling those when the need actually arises, not preemptively.&lt;/p&gt;

&lt;p&gt;Simple code is easier to debug, onboard into, and extend. Stick to what’s necessary — and nothing more.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. YAGNI principle
&lt;/h2&gt;

&lt;p&gt;YAGNI stands for “You Aren’t Gonna Need It,” and it’s a principle that encourages engineers to focus only on what’s necessary — not what &lt;em&gt;might&lt;/em&gt; be needed in the future. It opposes the temptation to overbuild features or add extra layers of functionality “just in case.”&lt;/p&gt;

&lt;p&gt;In practice, this means resisting the urge to anticipate every possible use case or future requirement. Even though it’s good to plan ahead, building for hypothetical scenarios could lead to bloated, complex codebases filled with unused logic and features. This not only wastes time but also increases the chances of introducing bugs and confusion.&lt;/p&gt;

&lt;p&gt;By following the YAGNI principle, developers stay focused on implementing actual, verified requirements — functionality that is needed now, not later. It encourages shipping lean, working software sooner and iterating based on actual user feedback rather than speculation. It also allows for better maintainability and makes the code easier to refactor or scale when real needs are clear.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Testing
&lt;/h2&gt;

&lt;p&gt;Testing is a non-negotiable part of software development. It makes sure your code does what it’s supposed to do — not just in best-case scenarios, but under real-world conditions too.&lt;/p&gt;

&lt;p&gt;Good tests basically act like a safety net. They catch bugs early, prevent regressions, and give you peace of mind when refactoring or adding new features. Without tests, even small changes can be unpredictable and risky.&lt;/p&gt;

&lt;p&gt;There are different types of testing — unit tests for individual functions, integration tests for how parts of the system work together, and end-to-end tests that simulate actual user interactions. While not every line of code needs a test, the goal is to cover the parts that are critical to functionality and prone to change.&lt;/p&gt;

&lt;p&gt;Testing your code not only improves your software — it also allows better collaboration. If tests exist, new developers can confidently make changes without worrying they're breaking something that already works.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Design before Coding
&lt;/h2&gt;

&lt;p&gt;Jumping straight into code might feel productive, but without a clear plan, you’re simply setting yourself up for rework and confusion down the line. “Design before coding” simply means thinking through your solution before you start typing.&lt;/p&gt;

&lt;p&gt;But this doesn’t always mean drawing detailed &lt;a href="https://www.geeksforgeeks.org/unified-modeling-language-uml-introduction/" rel="noopener noreferrer"&gt;UML diagrams&lt;/a&gt; or writing pages of documentation. It can be as simple as sketching out a flow, defining data models, or breaking a problem into smaller parts. The goal is to clarify &lt;em&gt;what&lt;/em&gt; you’re building and &lt;em&gt;how&lt;/em&gt; the pieces fit together — before you start implementing.&lt;/p&gt;

&lt;p&gt;Whether you’re building a feature, designing an API, or structuring a system, taking time to plan before you build leads to better outcomes — for both your code and your team.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Code Reviews
&lt;/h2&gt;

&lt;p&gt;Code reviews are more than just a quality check —they’re a collaborative process that helps teams grow, catch issues early, and maintain a consistent codebase.&lt;/p&gt;

&lt;p&gt;A good review isn’t just about pointing out bugs or nitpicking syntax. It’s about understanding the intent behind the code, offering constructive feedback, and suggesting improvements that make the code cleaner, more efficient, or easier to understand. It’s also an opportunity to learn from each other — whether it's discovering a new pattern, a better naming convention, or a smarter approach.&lt;/p&gt;

&lt;p&gt;Code review avoids bottlenecks, reduces technical debt, and makes sure the code is consistent with team standards. It also spreads knowledge across the team — when multiple people understand how a feature works, no one person becomes a single point of failure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Following best practices is not just about writing cleaner code; it’s about building a more efficient, collaborative, and future-ready development process. By incorporating these principles into your workflow, you’ll create software that’s not only high-quality but also easier to maintain, scale, and adapt as your projects grow.&lt;/p&gt;

&lt;p&gt;Adopting these best practices today will not only save you time but also set you up for long-term success, making sure you stay ahead in the tech industry.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>softwareengineering</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Why is Next.js so slow for developers?</title>
      <dc:creator>Christian Mbah</dc:creator>
      <pubDate>Wed, 07 May 2025 15:38:50 +0000</pubDate>
      <link>https://dev.to/chrismbah/why-is-nextjs-so-slow-for-developers-1gl9</link>
      <guid>https://dev.to/chrismbah/why-is-nextjs-so-slow-for-developers-1gl9</guid>
      <description>&lt;p&gt;I've been building apps with &lt;strong&gt;Next.js&lt;/strong&gt; for months now. Its built-in routing, SEO support, and other benefits made it a no-brainer over plain React when building full-stack web applications. But there’s one thing that’s been consistently frustrating:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;The development speed is painfully slow.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Next.js Hot Reload&lt;/strong&gt; is supposed to make updates from your code to the browser faster, but really, every small code change feels like waiting for a full rebuild. I experience freezing pages and lagging terminals, even when working on something as simple as a landing page. It really makes me question if this is truly the &lt;em&gt;"React on steroids"&lt;/em&gt; that everyone talks about.&lt;/p&gt;

&lt;p&gt;I've worked on &lt;strong&gt;Vite + React&lt;/strong&gt; projects, and I recalled the development speed was never this slow regardless of how complex the project was, so I decided to run up a simple Vite + React and Next.js project to contrast their speed, and within minutes, I noticed that the Vite + React app was A LOT faster, and it wasn't even close. There were no page reloads, no rebuild delays—just instant feedback.&lt;/p&gt;

&lt;p&gt;So this begs the question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;If Vite can give this kind of developer experience, why is Next.js still so far behind?&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The Reality of Next.js in a Development Environment
&lt;/h2&gt;

&lt;p&gt;When you look at the marketing for Next.js, it seems like a great solution for React developers (and it is). It offers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;✅Built-in routing&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;✅Server-side rendering (SSR)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;✅API routes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;✅SEO optimization&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;✅Full stack capabilities&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But there's a downside; Next.js can sometimes feel like it's working against you during development.&lt;/p&gt;

&lt;p&gt;Every time you save a file, the terminal starts multiple rebuilds. The browser refreshes slowly, and if you're working on a large, complex application or have many dynamic routes, it gets even worse. Navigating to a different route takes a lot of time, and it's not just your machine causing this (which I initially thought). So then...&lt;/p&gt;

&lt;h2&gt;
  
  
  Why is Next.js so slow?
&lt;/h2&gt;

&lt;p&gt;After a little bit of research, I realized it isn’t actually a “me” problem; many developers have shared their frustration online:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/76408504/nextjs-13-is-insanely-slow-in-dev-environment" rel="noopener noreferrer"&gt;“Next.js is insanely slow in dev mode” – StackOverflow thread&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.reddit.com/r/nextjs/comments/1b3qlwt/dev_is_painfully_slow/" rel="noopener noreferrer"&gt;"Next.js is painfully slow" - Reddit post&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.reddit.com/r/nextjs/comments/14on8ug/nextjs_is_extremely_slow/" rel="noopener noreferrer"&gt;"Next.js is extremely slow" - Reddit post&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After more digging, I realized that it comes down to how the framework is built under the hood. Here’s what I found:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Next.js Compiles Everything — Client And Server
&lt;/h3&gt;

&lt;p&gt;As a full-stack framework, Next.js isn’t just compiling your frontend like Vite does; it’s compiling both the frontend and the backend at once. So this means every time you hit save, the Next.js compiler has to figure out:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Does this affect the client? The server? or Both?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;...then it rebuilds accordingly. So it kind of makes sense that a one-line tweak might still trigger a chain reaction that takes seconds instead of milliseconds (not very efficient, in my opinion).&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Hot Reload ≠ Hot Module Replacement
&lt;/h3&gt;

&lt;p&gt;Next.js uses &lt;a href="https://nextjs.org/docs/architecture/fast-refresh" rel="noopener noreferrer"&gt;React Fast Refresh&lt;/a&gt;, which is supposed to preserve component state between edits. But in practice, especially in larger apps, Fast Refresh is slower, less predictable, and sometimes triggers a full page reload anyway.&lt;/p&gt;

&lt;p&gt;Meanwhile, Vite uses native ESM and &lt;a href="https://vite.dev/guide/features#hot-module-replacement" rel="noopener noreferrer"&gt;Hot Module Replacement (HMR)&lt;/a&gt;, so it only swaps the module that changed without doing extra work. It’s way lighter.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Still Built on Webpack (Unless You Switch to Turbopack)
&lt;/h3&gt;

&lt;p&gt;By default, Next.js still uses &lt;a href="https://nextjs.org/docs/app/api-reference/config/next-config-js/webpack" rel="noopener noreferrer"&gt;Webpack&lt;/a&gt; in dev mode — and Webpack is not known for speed. It was designed before ESM became mainstream, and it rebuilds too much by default.&lt;/p&gt;

&lt;p&gt;Vite, on the other hand, uses &lt;a href="https://vite.dev/config/build-options" rel="noopener noreferrer"&gt;esbuild&lt;/a&gt; (written in Go) and rollup for production. The difference is a lot, and for reference, Vite can cold-start a dev server in under 300–500 ms, while Next.js sometimes takes 10–20 seconds or more in a mid-size project.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. File Watching
&lt;/h3&gt;

&lt;p&gt;Next.js watches &lt;em&gt;a lot&lt;/em&gt; of files. This includes &lt;strong&gt;components&lt;/strong&gt;, &lt;strong&gt;pages&lt;/strong&gt;, &lt;strong&gt;layouts&lt;/strong&gt;, &lt;strong&gt;server functions&lt;/strong&gt;, and basically any &lt;strong&gt;custom config&lt;/strong&gt; files. So if you have a large number of routes/components, Next.js file-watching gets heavier and can hit your CPU hard, making things feel slower.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Your Machine is Still a Factor
&lt;/h3&gt;

&lt;p&gt;If you're running both server-side and client-side code locally (which you are with Next.js), your laptop or PC ends up doing a lot more work than in a basic client-only setup, and if you don't have a mid- to high-end PC, the developer experience can be frustrating.&lt;/p&gt;

&lt;h2&gt;
  
  
  Workarounds &amp;amp; Solutions
&lt;/h2&gt;

&lt;p&gt;To be fair, Next.js &lt;strong&gt;IS&lt;/strong&gt; a full-stack framework, so it does a lot under the hood; so for a better developer experience, there are some things you can tweak to improve the speed:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Try Turbopack with next dev --turbo
&lt;/h3&gt;

&lt;p&gt;Vercel is currently working on &lt;a href="https://vercel.com/blog/turbopack" rel="noopener noreferrer"&gt;Turbopack&lt;/a&gt;, their Webpack replacement written in Rust. It’s still in early stages, but it can offer faster refresh times — especially in smaller apps.&lt;/p&gt;

&lt;p&gt;You can use Turbopack in your app by replacing the &lt;code&gt;dev&lt;/code&gt; script in your &lt;code&gt;package.json&lt;/code&gt; file with &lt;code&gt;next dev --turbopack&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"dev"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"next dev --turbopack"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Keep Pages and Components Small
&lt;/h3&gt;

&lt;p&gt;It’s simple logic that &lt;em&gt;big files = bigger rebuilds&lt;/em&gt;, regardless of the framework. If you split your app into smaller components and pages, you reduce the surface area that triggers a rebuild.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Lazy-Load Heavier Routes or Components
&lt;/h3&gt;

&lt;p&gt;If you’re importing a huge component statically, it gets bundled into everything. Use &lt;a href="https://nextjs.org/learn/seo/dynamic-import-components" rel="noopener noreferrer"&gt;Next,js dynamic import&lt;/a&gt; &lt;code&gt;dynamic()&lt;/code&gt; to load heavy UI or logic only when needed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;dynamic&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;next/dynamic&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;HeavyComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;dynamic&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../components/HeavyComponent&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Offload Your Backend
&lt;/h3&gt;

&lt;p&gt;If you're doing API stuff inside &lt;a href="https://nextjs.org/docs/pages/building-your-application/routing/api-routes" rel="noopener noreferrer"&gt;Next.js api routes&lt;/a&gt; (&lt;code&gt;/api&lt;/code&gt;), it might slow things down, so try separating your backend into a service (like Firebase, Supabase, or even a separate Express API) during development. This will lighten things up for the compiler.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;So with all these said, should you ditch Next.js? Well, it depends.&lt;/p&gt;

&lt;p&gt;It’s easy to get frustrated (I’ve been there), but &lt;strong&gt;context&lt;/strong&gt; matters. Here’s how I think about it now:&lt;/p&gt;

&lt;h3&gt;
  
  
  When Next.js Makes Sense
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You’re building a full-stack app with server-side logic&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You need SEO optimization or static generation&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also, Next.js performance optimizations, image handling, SSR, and edge capabilities are great in production.&lt;/p&gt;

&lt;h3&gt;
  
  
  When Vite Might Be Better
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You’re building a frontend-heavy app or design tool&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You want instant feedback during development&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You’re prototyping and speed matters more than structure&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For dev experience (especially speed), Vite is just better right now.&lt;/p&gt;

&lt;p&gt;So what has been your experience so far with Next.js? Have you run into the same dev-speed issues? Did Turbopack help, or did you eventually switch to something like Vite? &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Feel free to share your thoughts in the comments.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>react</category>
      <category>nextjs</category>
    </item>
  </channel>
</rss>
