<?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: Dorcas Nyamekye Quaye</title>
    <description>The latest articles on DEV Community by Dorcas Nyamekye Quaye (@dorcie-dee).</description>
    <link>https://dev.to/dorcie-dee</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%2F3360071%2F66ee34f9-0a4c-4c37-bea9-541096474ad4.png</url>
      <title>DEV Community: Dorcas Nyamekye Quaye</title>
      <link>https://dev.to/dorcie-dee</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dorcie-dee"/>
    <language>en</language>
    <item>
      <title>Stop Copying ObjectIDs: Use Slugify in Your Node.js API (E-Commerce)</title>
      <dc:creator>Dorcas Nyamekye Quaye</dc:creator>
      <pubDate>Thu, 04 Sep 2025 17:54:24 +0000</pubDate>
      <link>https://dev.to/dorcie-dee/stop-copying-objectids-use-slugify-in-your-nodejs-api-e-commerce-3n1g</link>
      <guid>https://dev.to/dorcie-dee/stop-copying-objectids-use-slugify-in-your-nodejs-api-e-commerce-3n1g</guid>
      <description>&lt;p&gt;I used to spend extra time &lt;strong&gt;copying database ObjectIDs&lt;/strong&gt; when testing my endpoints. I'd be creating categories, products, and all kinds of CRUD operations, only to dig through the database for IDs every time.&lt;/p&gt;

&lt;p&gt;Then I discovered &lt;strong&gt;slugify&lt;/strong&gt;, a small Node.js package that makes URLs readable, SEO-friendly, and much easier to test. Suddenly, instead of typing &lt;code&gt;/categories/6489f3a2b6c1f7a12345&lt;/code&gt;, I could just type &lt;code&gt;/categories/mens-clothing&lt;/code&gt; and keep moving.&lt;/p&gt;




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

&lt;p&gt;Slugify is a simple Node.js package that converts strings into &lt;strong&gt;URL-friendly “slugs.”&lt;/strong&gt; It’s user-friendly, lowercase, hyphenates spaces, and removes unsafe characters, making URLs clean and readable.&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 plaintext"&gt;&lt;code&gt;"Men's Clothing" → "mens-clothing"
"Café &amp;amp; Restaurant!" → "cafe-restaurant"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is especially useful for &lt;strong&gt;categories, products, or any resource you want to make readable in a URL.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Don’t Confuse Slugify with Basic String Methods
&lt;/h2&gt;

&lt;p&gt;It’s important not to confuse &lt;strong&gt;slugify&lt;/strong&gt; with just using basic string methods like &lt;code&gt;trim()&lt;/code&gt; or &lt;code&gt;toLowerCase()&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;trim()&lt;/code&gt; only &lt;strong&gt;removes spaces at the start or end&lt;/strong&gt; of a string:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;  Men's Clothing  &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// "Men's Clothing"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;toLowerCase()&lt;/code&gt; only &lt;strong&gt;converts letters to lowercase&lt;/strong&gt;, but leaves spaces and special characters untouched:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Men's Clothing&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// "men's clothing"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you combine them:&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;  Men's Clothing  &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// "men's clothing"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You still end up with &lt;strong&gt;spaces and special characters&lt;/strong&gt;, which isn’t URL-friendly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Slugify, on the other hand, does all of this in one step:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Converts to lowercase&lt;/li&gt;
&lt;li&gt;Replaces spaces with hyphens&lt;/li&gt;
&lt;li&gt;Removes or replaces unsafe characters
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;slugify&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;slugify&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;slugify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;  Men's Clothing  &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;lower&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;// "mens-clothing"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the string is &lt;strong&gt;clean, readable, and ready for a URL&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Use Slugify in E-commerce?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;SEO-Friendly URLs&lt;/strong&gt; – Search engines prefer meaningful, readable URLs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Better UX&lt;/strong&gt; – Users can read and remember URLs easily.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Simpler Routing&lt;/strong&gt; – Fetch resources by slug instead of ID.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Easier Testing &amp;amp; Debugging&lt;/strong&gt; – From a developer perspective, using slugs saves you from copying database IDs every time you test an endpoint. You can type a readable slug like &lt;code&gt;mens-clothing&lt;/code&gt; and test your routes faster.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;For me, this made testing category endpoints much simpler. Every category I create now has a slug, and I can remember or type it easily without digging into the database.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  How I Implemented It in Node.js
&lt;/h2&gt;

&lt;p&gt;First, install the package:&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;slugify
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, use it when creating a new category:&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;slugify&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;slugify&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;categoryName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Men's Clothing&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;//convert to slug&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;categorySlug&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;slugify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;categoryName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;lower&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;//save in DB&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newCategory&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;Category&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; 
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;categoryName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
  &lt;span class="na"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;categorySlug&lt;/span&gt; 
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, instead of &lt;code&gt;/categories/6489f3a2b6c1f7a12345&lt;/code&gt;, your URL looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/categories/mens-clothing
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Some Use Cases of Slugify:
&lt;/h2&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%2Fmxsszeaqufy566up64sx.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%2Fmxsszeaqufy566up64sx.png" alt=" " width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Takeaway
&lt;/h2&gt;

&lt;p&gt;Slugify isn’t just about &lt;strong&gt;SEO&lt;/strong&gt; or user-friendly URLs—it’s also &lt;strong&gt;a huge help for backend developers&lt;/strong&gt;. It makes testing, debugging, and working with CRUD endpoints much simpler.&lt;/p&gt;

&lt;p&gt;If you’re building categories, products, or other resources for a web app, I highly recommend giving it a try. Clean URLs, easier testing, happy developers, happy users!&lt;/p&gt;

</description>
      <category>backenddevelopment</category>
      <category>node</category>
      <category>webdev</category>
      <category>api</category>
    </item>
    <item>
      <title>My First Steps with Socket.IO: Real-Time Updates Made Simple</title>
      <dc:creator>Dorcas Nyamekye Quaye</dc:creator>
      <pubDate>Mon, 25 Aug 2025 11:55:15 +0000</pubDate>
      <link>https://dev.to/dorcie-dee/my-first-steps-with-socketio-real-time-updates-made-simple-40o4</link>
      <guid>https://dev.to/dorcie-dee/my-first-steps-with-socketio-real-time-updates-made-simple-40o4</guid>
      <description>&lt;p&gt;Until now, I’ve mostly worked with &lt;strong&gt;RESTful APIs&lt;/strong&gt; where requests and responses follow a one-way flow (using &lt;strong&gt;HTTP&lt;/strong&gt;). Basically, the client asks for something → the server replies → and that’s it.&lt;/p&gt;

&lt;p&gt;But this time around, I had to bring in &lt;strong&gt;Socket.IO&lt;/strong&gt;. And I quickly asked myself: &lt;em&gt;how different is this from HTTP?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Well, HTTP is just request and response. The client makes a call, and the server gives a fixed reply. If you want new updates, you have to ask again and again.&lt;/p&gt;

&lt;p&gt;With Socket.IO, it feels different — it gives you &lt;strong&gt;live updates&lt;/strong&gt; without you always needing to call the server.&lt;/p&gt;




&lt;h3&gt;
  
  
  🌐 A Simple Analogy
&lt;/h3&gt;

&lt;p&gt;Think of &lt;strong&gt;HTTP&lt;/strong&gt; as writing letters ✉️.&lt;br&gt;
You send one, wait for a reply, then send another.&lt;/p&gt;

&lt;p&gt;Now, think of &lt;strong&gt;WebSocket/Socket.IO&lt;/strong&gt; as a phone call 📞.&lt;br&gt;
Once connected, both sides can talk freely without hanging up each time.&lt;/p&gt;

&lt;p&gt;That simple picture helped me understand it better.&lt;/p&gt;


&lt;h3&gt;
  
  
  👩‍💻 How I Set It Up
&lt;/h3&gt;

&lt;p&gt;So this is how I set it up the first time I tried Socket.IO 👇&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. On the Node.js backend:&lt;/strong&gt;&lt;br&gt;
Normally, I’d just do:&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="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 listening on $PORT`&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;But this time, since I wanted to add Socket.IO, I had to wrap my app with an HTTP server and then use &lt;code&gt;server.listen&lt;/code&gt; instead. I also set it up to send &lt;strong&gt;live updates&lt;/strong&gt; (in this case, “new posts”) to the client:&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="k"&gt;from&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createServer&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Server&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;socket.io&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createServer&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;io&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;Server&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;cors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;origin&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;io&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;connection&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;socket&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Client connected&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Send a "new post" update every 5 seconds&lt;/span&gt;
  &lt;span class="nf"&gt;setInterval&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;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;emit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;newPost&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;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;📢 New update just arrived!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;This is a live post pushed from the server&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="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;disconnect&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="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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Client disconnected&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;server&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 listening on $PORT`&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;&lt;strong&gt;2. On the React client:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Then, I went to the client side and connected it 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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;io&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;socket.io-client&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;socket&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;io&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http://localhost:6002&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Listen for live post updates&lt;/span&gt;
&lt;span class="nx"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;newPost&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;data&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Live update:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&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="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="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;content&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;h3&gt;
  
  
  ✨ Wrapping Up
&lt;/h3&gt;

&lt;p&gt;So that’s how I first set it up — changing my &lt;code&gt;app.listen&lt;/code&gt; to &lt;code&gt;server.listen&lt;/code&gt;, and then configuring both sides so the server could &lt;strong&gt;push live updates&lt;/strong&gt; straight to the client.&lt;/p&gt;

&lt;p&gt;This was my very first introduction to Socket.IO, and it already made sense how powerful it can be for things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Live chat&lt;/li&gt;
&lt;li&gt;Notifications&lt;/li&gt;
&lt;li&gt;Collaborative apps&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I know there’s still much more to learn, but this was a great starting point. If you’ve worked with Socket.IO before and have tips or resources, I’d love to hear them 😁&lt;/p&gt;

</description>
      <category>backend</category>
      <category>webdev</category>
      <category>discuss</category>
      <category>react</category>
    </item>
    <item>
      <title>How .aggregate() Powered Our Learner &amp; Income Analytics in MongoDB</title>
      <dc:creator>Dorcas Nyamekye Quaye</dc:creator>
      <pubDate>Sat, 09 Aug 2025 22:33:16 +0000</pubDate>
      <link>https://dev.to/dorcie-dee/how-aggregate-powered-our-learner-income-analytics-in-mongodb-jdg</link>
      <guid>https://dev.to/dorcie-dee/how-aggregate-powered-our-learner-income-analytics-in-mongodb-jdg</guid>
      <description>&lt;p&gt;This week, I worked on something exciting: &lt;strong&gt;reports routes&lt;/strong&gt; for our backend. This is the part of the system that helps admins see important data at a glance. My job was to build endpoints that could transform raw learner and payment data into meaningful insights, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A list of &lt;strong&gt;all learners&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;The number of &lt;strong&gt;learners per track&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;total income&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;income per track&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In short, I wasn’t just fetching data anymore. I was shaping it into something an admin could actually use to make decisions.&lt;/p&gt;

&lt;p&gt;Pretty straightforward on paper, but here’s where the twist came in. I had to use MongoDB’s &lt;code&gt;.aggregate()&lt;/code&gt; for the first time.&lt;/p&gt;

&lt;p&gt;Before this, I had been living in the world of &lt;code&gt;.find()&lt;/code&gt; and &lt;code&gt;.findOne()&lt;/code&gt;. They were my comfort zone; very simple, direct, and predictable. But for this task, I needed more power: grouping data, filtering it, reshaping fields, and running calculations all in one go. That’s where &lt;code&gt;.aggregate()&lt;/code&gt; stepped in.&lt;/p&gt;

&lt;p&gt;One of my tasks was to get the number of learners in each track &lt;strong&gt;only if they had paid&lt;/strong&gt;. With &lt;code&gt;.aggregate()&lt;/code&gt;, I learned I could:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Filter&lt;/strong&gt; with &lt;code&gt;$match&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Group&lt;/strong&gt; with &lt;code&gt;$group&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Count or sum&lt;/strong&gt; fields using &lt;code&gt;$sum&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reshape or limit fields&lt;/strong&gt; with &lt;code&gt;$project&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here’s a little snippet from what I wrote:&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;result&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;learnerModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;aggregate&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;$match&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;paid&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="na"&gt;$group&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;$track&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;$sum&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&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="na"&gt;$project&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;track&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="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;_id&lt;/span&gt;&lt;span class="p"&gt;:&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;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, &lt;code&gt;$project&lt;/code&gt; let me clean up the output by renaming &lt;code&gt;_id&lt;/code&gt; to &lt;code&gt;track&lt;/code&gt; and hiding unnecessary fields.&lt;/p&gt;

&lt;p&gt;Seeing the data come out exactly as I needed — filtered, grouped, and neatly shaped — felt so satisfying. It was like discovering that MongoDB had been quietly hiding a mini data-analytics tool inside it all along.&lt;/p&gt;

&lt;p&gt;This experience was more than just adding new routes. I learned a new way of thinking about database queries, and I’m already imagining all the other problems &lt;code&gt;.aggregate()&lt;/code&gt; could help me solve.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>backend</category>
      <category>api</category>
    </item>
    <item>
      <title>My First Dive into Real Payments Integration (with Paystack and Webhooks)</title>
      <dc:creator>Dorcas Nyamekye Quaye</dc:creator>
      <pubDate>Sat, 02 Aug 2025 12:04:23 +0000</pubDate>
      <link>https://dev.to/dorcie-dee/my-first-dive-into-real-payments-integration-with-paystack-and-webhooks-3nmg</link>
      <guid>https://dev.to/dorcie-dee/my-first-dive-into-real-payments-integration-with-paystack-and-webhooks-3nmg</guid>
      <description>&lt;p&gt;This week, I did something that felt both exciting and intimidating. I &lt;strong&gt;integrated a payment gateway&lt;/strong&gt; into one of my backend APIs for the very first time,  even if it was just in test mode. 🙈💳&lt;/p&gt;

&lt;p&gt;Now, I’ve created APIs before, like user authentication, CRUD operations, and more. But this time? I wanted my API to &lt;strong&gt;handle actual payments&lt;/strong&gt; and that felt like stepping into a new territory.&lt;/p&gt;




&lt;h3&gt;
  
  
  ☺️ Why I Took This On
&lt;/h3&gt;

&lt;p&gt;I’ve been working on an API where &lt;strong&gt;learners can register for a course track&lt;/strong&gt;. I already had the backend logic for signing up, viewing courses, and assigning users to tracks. But I had to take it a step further:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What if learners could also pay and automatically get an invoice confirmation?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So I jumped into payment processing for the first time with no real business setup, just the &lt;strong&gt;test mode&lt;/strong&gt; that Paystack provides to simulate real-life transactions.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔄 Here’s What I Built
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Invoice Generation&lt;/strong&gt;: When a learner is about to pay for a course, the backend creates an invoice showing the amount, due date, Paystack payment link , and learner info.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verify Payment Endpoint&lt;/strong&gt;: I created a &lt;code&gt;/verify-payment&lt;/code&gt; endpoint to verify if a transaction is real. This uses the Paystack verification API to confirm that the payment went through. This helped me ensure the payment wasn’t faked or interrupted.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Webhook Integration&lt;/strong&gt;: This was the exciting part. I set up a &lt;code&gt;/webhook&lt;/code&gt; route to receive notifications from Paystack.  &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  🤔 Wait… What’s a Webhook?
&lt;/h3&gt;

&lt;p&gt;Let me explain it the way I finally got it:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Imagine you order food from a restaurant (you = your backend app). You don’t want to keep calling them to ask, "Is the food ready yet?"&lt;/p&gt;

&lt;p&gt;Instead, you tell them: “Here’s my number. Just &lt;strong&gt;call me&lt;/strong&gt; when the food is ready.”&lt;/p&gt;

&lt;p&gt;That &lt;strong&gt;call&lt;/strong&gt; is the webhook.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In my case, Paystack is the restaurant. After the payment, it sends a &lt;strong&gt;POST request&lt;/strong&gt; to my backend automatically, containing details of the transaction. &lt;/p&gt;

&lt;p&gt;That way, even if a user closes their browser or their internet drops, my backend still gets notified when a payment succeeds and I don’t have to keep asking their API whether the transaction went through.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I made sure that the webhook was &lt;strong&gt;idempotent&lt;/strong&gt; (fancy word for: “Don’t repeat yourself”). &lt;/li&gt;
&lt;li&gt;Even if Paystack sends the same webhook multiple times, my backend only updates the invoice &lt;strong&gt;once&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  👩🏽‍💻 Lessons I Learned
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Test mode&lt;/strong&gt; is a lifesaver. You can simulate payments without using real money.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Payment processing isn’t as scary&lt;/strong&gt; as it sounds once you break it down.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Webhooks are super useful&lt;/strong&gt; when you don’t want to poll third-party APIs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security matters&lt;/strong&gt; cause I had to validate incoming webhook signatures to avoid spoofing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I’m still early in my journey as a backend developer, but this week felt like a level-up, seeing my app &lt;strong&gt;respond to real-world actions&lt;/strong&gt; like a payment, and handle them intelligently.&lt;/p&gt;




&lt;h3&gt;
  
  
  💬 Now Share With Me
&lt;/h3&gt;

&lt;p&gt;Have you tried integrating payment in your project? What platform did you use (Paystack, Stripe, Flutterwave…)? What was your first challenge?&lt;/p&gt;

&lt;p&gt;Let me know in the comments or feel free to ask questions if you’re about to try it!&lt;/p&gt;

</description>
      <category>backend</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Bringing .populate() &amp; .virtual() to The Party</title>
      <dc:creator>Dorcas Nyamekye Quaye</dc:creator>
      <pubDate>Sun, 27 Jul 2025 13:06:17 +0000</pubDate>
      <link>https://dev.to/dorcie-dee/bringing-populate-virtual-to-the-party-fgg</link>
      <guid>https://dev.to/dorcie-dee/bringing-populate-virtual-to-the-party-fgg</guid>
      <description>&lt;p&gt;This week, I &lt;em&gt;got&lt;/em&gt; the concept of &lt;code&gt;.populate()&lt;/code&gt; and &lt;code&gt;.virtual()&lt;/code&gt; in Mongoose, and it clicked with a Wi-Fi analogy.&lt;/p&gt;




&lt;h3&gt;
  
  
  📡 Picture This…
&lt;/h3&gt;

&lt;p&gt;Imagine your &lt;strong&gt;Wi-Fi router&lt;/strong&gt; is a &lt;strong&gt;Track&lt;/strong&gt; in your database. It doesn’t store a list of who’s connected. It just exists.&lt;/p&gt;

&lt;p&gt;Now, picture your &lt;strong&gt;laptop&lt;/strong&gt; as &lt;strong&gt;Courses&lt;/strong&gt;. It &lt;em&gt;knows&lt;/em&gt; what Wi-Fi it's connected to. That means the Course will have a field like &lt;code&gt;track: Types.ObjectId&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your &lt;strong&gt;Course&lt;/strong&gt; (laptop) &lt;em&gt;remembers&lt;/em&gt; which &lt;strong&gt;Track&lt;/strong&gt; (router) it’s connected to.&lt;/li&gt;
&lt;li&gt;If you want to show more about the track (like its name), you just &lt;code&gt;.populate()&lt;/code&gt; it.&lt;/li&gt;
&lt;li&gt;It’s like your laptop saying:&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;“I’ve saved this Wi-Fi ID. Show me more about it.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That’s &lt;code&gt;.populate()&lt;/code&gt;. It  fetches full data from the referenced document.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔄 Now flip it…
&lt;/h3&gt;

&lt;p&gt;Let's go back to the &lt;strong&gt;router&lt;/strong&gt; (Track). It doesn’t &lt;em&gt;store&lt;/em&gt; a list of all devices connected to it. But you can make it show them with &lt;code&gt;.virtual()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You define a virtual field like:&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="nx"&gt;trackSchema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;virtual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;courses&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;ref&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Course&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;localField&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="na"&gt;foreignField&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;track&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;p&gt;Then when you fetch a track and call &lt;code&gt;.populate('courses')&lt;/code&gt;, it goes like:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Okay, let me go and find all Courses where &lt;code&gt;track === my ID&lt;/code&gt; and list them here.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So &lt;code&gt;.virtual()&lt;/code&gt; doesn’t store the connection. It just knows where to look.&lt;/p&gt;




&lt;h3&gt;
  
  
  😎 Why It Matters
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Devices (Course) use &lt;code&gt;.populate()&lt;/code&gt; because they know what router (Track) they’re connected to.&lt;/p&gt;

&lt;p&gt;The Router (Track) uses &lt;code&gt;.virtual()&lt;/code&gt; because it doesn’t know who’s connected, but it can go look.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;.virtual()&lt;/code&gt; keeps your document clean. That means when you check your &lt;strong&gt;Track&lt;/strong&gt; documents in the database, you won’t find a bloated list of every related &lt;strong&gt;Course&lt;/strong&gt; inside each one.&lt;/p&gt;

&lt;p&gt;Real-world backend structure is all about &lt;strong&gt;scalability&lt;/strong&gt; and &lt;strong&gt;efficiency&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.virtual()&lt;/code&gt; is scalable in action.&lt;/p&gt;

&lt;p&gt;So for anyone trying to get their head around Mongoose relationships?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Just remember:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Devices populate. Router virtual.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>backend</category>
      <category>api</category>
      <category>beginners</category>
      <category>learning</category>
    </item>
    <item>
      <title>Postman Was on raw&gt;Text... and Not raw&gt;JSON</title>
      <dc:creator>Dorcas Nyamekye Quaye</dc:creator>
      <pubDate>Fri, 18 Jul 2025 12:43:16 +0000</pubDate>
      <link>https://dev.to/dorcie-dee/hours-of-debugging-all-because-of-this-one-postman-mistake-28n7</link>
      <guid>https://dev.to/dorcie-dee/hours-of-debugging-all-because-of-this-one-postman-mistake-28n7</guid>
      <description>&lt;p&gt;&lt;strong&gt;Let me save you some time.&lt;/strong&gt; I spent hours debugging my backend routes, thinking the problem was my code, only to find out it was something way simpler.&lt;/p&gt;

&lt;p&gt;I was testing protected routes like:&lt;br&gt;
&lt;code&gt;GET /auth-user&lt;/code&gt;&lt;br&gt;
&lt;code&gt;PUT /update-profile&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;These routes required a valid JWT and expected a properly formatted request body (JSON). My backend was using:&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="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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And inside my controller, I was accessing data from &lt;code&gt;req.body&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Despite everything looking fine in the code, my request kept failing with errors like:&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="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;message&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Unauthorized: No user ID found&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;p&gt;Or worse, the route would hit, but the body would be &lt;code&gt;undefined&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I retested token flow, reconfigured middlewares, re-checked routes and controllers. But nothing worked.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;😫 The Real Issue? Postman Was Set to Text, Not JSON&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yup. That was it.&lt;br&gt;
In Postman, under &lt;code&gt;Body &amp;gt; raw&lt;/code&gt;, I had left it on &lt;code&gt;Text&lt;/code&gt;.&lt;br&gt;
So instead of sending:&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="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;fullName&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Dorcas Q&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;email&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dorcas@gmail.com&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;p&gt;It was sending plain text.&lt;br&gt;
The backend, expecting JSON, saw... nothing. &lt;code&gt;req.body&lt;/code&gt; was &lt;code&gt;undefined&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;When I finally realized I had left it in &lt;code&gt;raw &amp;gt; Text&lt;/code&gt; instead of &lt;code&gt;raw &amp;gt; JSON&lt;/code&gt;, I was both &lt;strong&gt;satisfied&lt;/strong&gt; and &lt;strong&gt;so annoyed&lt;/strong&gt; with myself. 😅&lt;br&gt;
Like &lt;em&gt;“Seriously? That’s what caused all this pain?”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔍The Lesson I Learnt&lt;/strong&gt;&lt;br&gt;
Sometimes the problem isn’t in your backend logic. It’s in the &lt;strong&gt;tools&lt;/strong&gt; you're using to test.&lt;br&gt;
This reminded me how easy it is to overlook the &lt;strong&gt;simple things&lt;/strong&gt;, especially when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You’re reusing old tabs that default back to &lt;code&gt;Text&lt;/code&gt; instead of &lt;code&gt;JSON&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;You’re testing authenticated endpoints, and your brain is fixated on JWT flows, headers, and controller logic.&lt;/li&gt;
&lt;li&gt;You’re just &lt;strong&gt;so tired&lt;/strong&gt; and have been debugging for hours (which I absolutely was).😁&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now? I no longer run a Postman test without &lt;strong&gt;double-checking&lt;/strong&gt; that it's set to &lt;code&gt;raw &amp;gt; JSON&lt;/code&gt;.&lt;br&gt;
And if you made the same mistake, please don’t beat yourself up. It happens. A lot more often than you’d think.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;✅ Final Tip&lt;/strong&gt;&lt;br&gt;
Before you start debugging controllers, token logic, or anything complex:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Double-check your Postman body type.&lt;/li&gt;
&lt;li&gt;Make sure it’s &lt;code&gt;raw &amp;gt; JSON&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Save yourself hours cause I wish I had.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;☺️ Now Over to You&lt;/strong&gt;&lt;br&gt;
Have you ever been stuck for hours only to realize it was something tiny like this?&lt;br&gt;
Let me know in the comments 👇&lt;/p&gt;

</description>
      <category>postman</category>
      <category>discuss</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Creating Authentication Endpoints Using Node.js &amp; Express.js</title>
      <dc:creator>Dorcas Nyamekye Quaye</dc:creator>
      <pubDate>Thu, 17 Jul 2025 13:21:26 +0000</pubDate>
      <link>https://dev.to/dorcie-dee/creating-authentication-endpoints-using-nodejs-expressjs-27fm</link>
      <guid>https://dev.to/dorcie-dee/creating-authentication-endpoints-using-nodejs-expressjs-27fm</guid>
      <description>&lt;p&gt;Imagine you are building an API with admin authentication. The kinds of auth endpoints you create will depend a lot on your app’s flow and needs.&lt;/p&gt;

&lt;p&gt;Any time I look at a UI design or wireframe, I try to identify what endpoints are &lt;em&gt;visibly&lt;/em&gt; needed. If it’s an admin authentication flow, the basics usually look like:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;POST /signup&lt;/code&gt;&lt;br&gt;
&lt;code&gt;POST /verify-otp&lt;/code&gt;&lt;br&gt;
&lt;code&gt;POST /login&lt;/code&gt;&lt;br&gt;
&lt;code&gt;POST /forgot-password&lt;/code&gt;&lt;br&gt;
&lt;code&gt;POST /reset-password&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;But I don’t stop there. I always ask myself:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“What backend endpoints don’t appear on the UI but are still crucial for secure and smooth functionality?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Sometimes I go blank, but that’s normal. In those moments, I just tell my AI assistant how I envision the project or hit up a dev friend in my DMs. If I’m working on something like a Student Management System, I usually break it down into categories:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Admin authentication&lt;/li&gt;
&lt;li&gt;Lesson creation&lt;/li&gt;
&lt;li&gt;Student enrollment, etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I either list what I think should be in that category and ask if I missed something, or I just ask, &lt;em&gt;“What else would you add or recommend if given the chance?”&lt;/em&gt; You’d be surprised the gems you get back from those convos.&lt;/p&gt;

&lt;p&gt;Doing this helps me build endpoints more intentionally, with security, scalability, and clean structure in mind. &lt;/p&gt;

&lt;p&gt;Oh, and something I keep reminding myself:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It doesn’t have to be perfect before your first GitHub push... or the second... or the twelfth.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Interestingly, this week, I’ve been working on an auth workflow and was given a recommended list of endpoints to build. That alone made things feel so much clearer. Isn’t that cute? 😄&lt;/p&gt;

&lt;p&gt;And funnily enough, that recommended list also opened my eyes to other useful endpoints, like:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;POST /resend-verification-otp&lt;/code&gt;&lt;br&gt;
&lt;code&gt;POST /change-password&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Sometimes, all it takes is a prompt from someone else, or a nudge from an AI to unlock that next layer of clarity.☺️&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Progress over perfection. Always.&lt;/strong&gt; Because even the most polished production apps didn’t start perfect. They evolved. Step by step. Tweak by tweak.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://github.com/Dorcie-dee/" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.linkedin.com/in/dorcasnyamekyequaye/" rel="noopener noreferrer"&gt;LinkedIn&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.upwork.com/freelancers/~01c39ece8535304b76" rel="noopener noreferrer"&gt;Upwork&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>backend</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
