<?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: DinmaOtutu</title>
    <description>The latest articles on DEV Community by DinmaOtutu (@dinmaotutu).</description>
    <link>https://dev.to/dinmaotutu</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%2F134829%2F33925408-1ffe-4ee6-b692-bdb793d9fdee.png</url>
      <title>DEV Community: DinmaOtutu</title>
      <link>https://dev.to/dinmaotutu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dinmaotutu"/>
    <language>en</language>
    <item>
      <title>Enhancing CMS Application Efficiency with Prisma Optimize</title>
      <dc:creator>DinmaOtutu</dc:creator>
      <pubDate>Wed, 13 Nov 2024 10:41:18 +0000</pubDate>
      <link>https://dev.to/dinmaotutu/enhancing-cms-application-efficiency-with-prisma-optimize-2op7</link>
      <guid>https://dev.to/dinmaotutu/enhancing-cms-application-efficiency-with-prisma-optimize-2op7</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In addition to quick query execution, high-performance applications need efficient and customized data retrieval. Prisma Optimize offers insights and suggestions to assist developers in finding bottlenecks, optimizing queries, and simplifying database interactions.&lt;/p&gt;

&lt;p&gt;Building on our &lt;a href="https://dev.to/dinmaotutu/building-a-high-performance-cms-with-nextjs-and-prisma-accelerate-19cj-temp-slug-4778182?preview=ac7e8688bdffeef6354115a3650fcdcd636682fdbbddb81d7ccb547fa5fcb404a653f859fc6507b8a6e20108dd22e37568be2390b36c5b15492e2dd9"&gt;Prisma Accelerate CMS project&lt;/a&gt;, we’ll add Prisma Optimize to measure and improve our query performance. By the end, you’ll see how Prisma Optimize’s recommendations can take a well-performing app to the next level.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;What is Prisma Optimize?&lt;/li&gt;
&lt;li&gt;Integrating Prisma Optimize into the CMS Project&lt;/li&gt;
&lt;li&gt;Using Prisma Optimize to Analyze Queries&lt;/li&gt;
&lt;li&gt;Applying Prisma Optimize Recommendations&lt;/li&gt;
&lt;li&gt;Insights on AI-Powered Recommendations&lt;/li&gt;
&lt;li&gt;Benchmarking Improvements&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  What is Prisma Optimize?
&lt;/h2&gt;

&lt;p&gt;Prisma Optimize improves Prisma ORM by pointing out ineffective database operations and making recommendations for improvements, like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Analysis of queries and insights into performance.&lt;/li&gt;
&lt;li&gt;Suggestions for indexing, cutting down on complete table scans, and over-fetching.&lt;/li&gt;
&lt;li&gt;AI-supported justifications for every suggestion to assist you in successfully implementing changes.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Integrating Prisma Optimize into the CMS Project
&lt;/h2&gt;

&lt;p&gt;Let’s add Prisma Optimize to our Prisma Accelerate CMS project by following these steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install Prisma Optimize packages
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install @prisma/client@latest @prisma/extension-optimize

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Update schema.prisma with Tracing In schema.prisma, add the tracing preview feature to the generator block:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["tracing"]
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Then, regenerate Prisma Client:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx prisma generate

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Log in to &lt;a href="https://console.prisma.io/" rel="noopener noreferrer"&gt;Data Proxy Platform&lt;/a&gt;, navigate your existing workspace, and click on &lt;code&gt;optimize&lt;/code&gt; at the top left corner bar.&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%2F4pqffd0twtbdcigfbjug.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%2F4pqffd0twtbdcigfbjug.jpg" alt="launch optimize" width="800" height="346"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click on &lt;code&gt;launch optimize&lt;/code&gt; which brings you to a new page &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%2F9iacvlqfa80sm3b0ha7v.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%2F9iacvlqfa80sm3b0ha7v.jpg" alt="setting icon" width="800" height="126"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click on the &lt;code&gt;settings&lt;/code&gt; icon to generate API keys&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%2F8yhxjzxtsikn5ycbgtl6.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%2F8yhxjzxtsikn5ycbgtl6.jpg" alt="create API key" width="800" height="165"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add Prisma Optimize API Key to your environment variables:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OPTIMIZE_API_KEY="YOUR_OPTIMIZE_API_KEY"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Extend Prisma Client with Prisma Optimize In your Prisma Client configuration file (src/lib/prisma.ts):
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { PrismaClient } from '@prisma/client';
import { withOptimize } from '@prisma/extension-optimize';
import { withAccelerate } from '@prisma/extension-accelerate';

const prisma = new PrismaClient().$extends(
  withOptimize({
    apiKey: process.env.OPTIMIZE_API_KEY, 
  })
).$extends(
  withAccelerate()
);

export default prisma;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Using Prisma Optimize to Analyze Queries
&lt;/h2&gt;

&lt;p&gt;To modify our existing code to incorporate Prisma Optimize, you can replace the &lt;code&gt;include&lt;/code&gt; statement from the &lt;code&gt;Post route&lt;/code&gt; with select to specify the fields you need. Here’s how you can do it:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Previous code&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export async function GET(req) {
  const posts = await prisma.post.findMany({
    include: { author: true, category: true },
    cacheStrategy: { ttl: 3600 }
  });
  return new Response(JSON.stringify(posts), {
    headers: { 'Content-Type': 'application/json' },
  });
}

to use this const posts = await prisma.post.findMany({
  select: { id: true, title: true, content: true },
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Updated Version&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export async function GET(req) {
  const posts = await prisma.post.findMany({
    select: {
      id: true,
      title: true,
      content: true,
      author: { select: { name: true } }, 
      category: { select: { name: true } }
    },
    cacheStrategy: { ttl: 3600 },
  });

  return new Response(JSON.stringify(posts), {
    headers: { 'Content-Type': 'application/json' },
  });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We use &lt;code&gt;select&lt;/code&gt; for post, author, and category to only fetch necessary fields, reducing payload size and optimizing performance.&lt;br&gt;
To modify your existing code to incorporate both Prisma Accelerate and the selective field retrieval from Prisma Optimize, we replaced the &lt;code&gt;include&lt;/code&gt; statement with &lt;code&gt;select&lt;/code&gt; to specify the fields we need. &lt;/p&gt;
&lt;h3&gt;
  
  
  Analyzing Queries With Prisma Optimize
&lt;/h3&gt;

&lt;p&gt;With Prisma Optimize setup, let’s record a session and analyze some queries from our CMS project.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start a Recording Session In the Prisma Optimize dashboard on Prisma Data Platform, click Start Recording to begin collecting query performance data.&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%2Fanp0sz5d4w5eykepfd6t.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%2Fanp0sz5d4w5eykepfd6t.jpg" alt="Start recording" width="800" height="108"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Run Queries in the Application such as loading posts, creating new users, or fetching categories. These interactions will be logged in the recording session for analysis.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Stop the Recording Session once you’ve captured enough queries, in the Prisma Optimize dashboard.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Analyze the Results and explore query metrics in Prisma Optimize because the dashboard displays query types, execution times, and recommended improvements. &lt;/p&gt;&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%2Fqdk7tfhngpc4pbgxwlxr.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%2Fqdk7tfhngpc4pbgxwlxr.jpg" alt="Captured query" width="800" height="444"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The recommendation by Prisma Optimize &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%2Fd9qtpd942lok5kmqjtzq.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%2Fd9qtpd942lok5kmqjtzq.jpg" alt="Result" width="800" height="442"&gt;&lt;/a&gt;&lt;br&gt;
From the recorded session, the current query to fetch posts has &lt;code&gt;Excessive number of rows returned&lt;/code&gt; and Prisma optimize recommends:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;We recommend using the take option to limit the number of entries returned by your queries:

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Applying Prisma Optimize Recommendations
&lt;/h2&gt;

&lt;p&gt;Let’s apply a few common recommendations Prisma Optimize suggests for our CMS project.&lt;/p&gt;

&lt;p&gt;Excessive number of rows returned&lt;br&gt;
&lt;strong&gt;Solution&lt;/strong&gt;: take option to limit the number of entries returned.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;prisma.post.findMany({
  take: 10, // Limits the number of results to 10
  // other query parameters
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Excessive Data Retrieval&lt;br&gt;
&lt;strong&gt;Solution&lt;/strong&gt;: Use select to fetch only required fields:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const posts = await prisma.post.findMany({
  select: { id: true, title: true, content: true },
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Insights on AI-Powered Recommendations
&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%2Fcjjam1i8n1qoemdspwzs.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%2Fcjjam1i8n1qoemdspwzs.jpg" alt="Recommendation" width="800" height="140"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Prisma Optimize uses AI to make suggestions and give you details that help you understand why a change is recommended. For example, if Prisma AI says that adding an index to a WHERE clause would make it work better, it will explain how the index could cut down on scan times. This advice is especially helpful for queries or models that are complicated, as it can be hard to figure out how an optimization will affect 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%2Fsnysn0ew9gzmgnbctuba.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%2Fsnysn0ew9gzmgnbctuba.jpg" alt="Response" width="800" height="633"&gt;&lt;/a&gt;&lt;br&gt;
I asked questions I needed clarification on based on recommendations and the above was the response from AI.&lt;/p&gt;


&lt;h2&gt;
  
  
  Benchmarking Improvements
&lt;/h2&gt;

&lt;p&gt;After applying Prisma Optimize’s recommendations, we measure the impact on query performance using benchmarking techniques.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export async function GET(req) {
  const posts = await prisma.post.findMany({ take: 10, select: { id: true, title: true } , cacheStrategy: { ttl: 3600 },})
  return new Response(JSON.stringify(posts), {
    headers: { 'Content-Type': 'application/json' },
  });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Initial Query Performance (Before Optimization)&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%2Fl1ej75rctckx55qu6kg0.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%2Fl1ej75rctckx55qu6kg0.jpg" alt="Before Optimization" width="800" height="140"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Optimized Query Performance (After Applying Recommendations)&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%2Fvew1qzzab472r87g4nb9.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%2Fvew1qzzab472r87g4nb9.jpg" alt="After optimization" width="800" height="350"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;## Performance Comparison Before and After Optimization

| Request           | Response Time Before Optimization | Response Time After Optimization |
|-------------------|-----------------------------------|----------------------------------|
| GET /api/posts    | 3975 ms                           | 265 ms                           |
| GET /api/posts    | 3975 ms                           | 154 ms                           |
| GET /api/posts    | 3975 ms                           | 106 ms                           |
| GET /api/posts    | 3975 ms                           | 158 ms                           |
| GET /api/posts    | 3975 ms                           | 118 ms                           |
| GET /api/posts    | 3975 ms                           | 128 ms                           |

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This table reflects the improvement in response times after optimization. &lt;br&gt;
All the codes can be found in this &lt;a href="https://github.com/DinmaOtutu/high-perform-cms" rel="noopener noreferrer"&gt;repository&lt;/a&gt;.&lt;/p&gt;




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

&lt;p&gt;Including Prisma Optimize in our Prisma Accelerate CMS project has shown how well-focused query optimizations improve application speed. Providing insightful analysis, also helps developers lower database load and increase response times.&lt;/p&gt;

&lt;p&gt;Prisma Optimize is best for applications that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Handle large datasets and require efficient data retrieval.&lt;/li&gt;
&lt;li&gt;Operate in serverless environments where database connections need to be managed effectively.&lt;/li&gt;
&lt;li&gt;Experience high traffic and need scalable solutions to maintain performance under load.&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Building a High-Performance CMS with Next.js and Prisma Accelerate</title>
      <dc:creator>DinmaOtutu</dc:creator>
      <pubDate>Wed, 13 Nov 2024 10:40:53 +0000</pubDate>
      <link>https://dev.to/dinmaotutu/building-a-high-performance-cms-with-nextjs-and-prisma-accelerate-3igd</link>
      <guid>https://dev.to/dinmaotutu/building-a-high-performance-cms-with-nextjs-and-prisma-accelerate-3igd</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Performance is critical in CMS(Content Management System) applications where users expect rapid content delivery and smooth navigation. Leveraging &lt;strong&gt;Prisma Accelerate&lt;/strong&gt; with &lt;strong&gt;Next.js&lt;/strong&gt; provides a powerful solution for high-performance database interaction.&lt;/p&gt;

&lt;p&gt;This article will walk you through how to set up Prisma Accelerate, create a simple CMS project, and benchmark its performance improvements. By the end, you’ll understand how it can reduce latency and optimize database load for a responsive, scalable CMS.&lt;/p&gt;




&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;What is Prisma Accelerate?&lt;/li&gt;
&lt;li&gt;Setting Up a CMS Project with Next.js&lt;/li&gt;
&lt;li&gt;Setting Up PostgreSQL and Prisma Accelerate&lt;/li&gt;
&lt;li&gt;Building CMS Functionality&lt;/li&gt;
&lt;li&gt;Benchmarking Prisma Accelerate&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  What is Prisma Accelerate?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Prisma Accelerate&lt;/strong&gt; is an add-on to the Prisma ORM designed to enhance database query performance through global caching and scalable connection pooling. It’s built to reduce database load and improve response times, particularly in data-heavy applications like CMS.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Features
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Global Caching&lt;/strong&gt;: Caches frequent database queries, reducing the need to access the database repeatedly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Connection Pooling&lt;/strong&gt;: Manages connections efficiently, allowing the application to handle a high volume of simultaneous queries without overwhelming the database.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By integrating Prisma Accelerate, Next.js applications can deliver faster, more reliable experiences, especially under heavy traffic.&lt;/p&gt;




&lt;h2&gt;
  
  
  Setting Up a CMS Project with Next.js
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Initialize the Next.js Project&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start by creating a new Next.js application.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-next-app high-perform-cms
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Navigate to the project folder and open it in your preferred IDE, the folder structure should look 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%2Fl122zxzfbwdroc9lkl09.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%2Fl122zxzfbwdroc9lkl09.jpg" alt="App folder structure" width="800" height="938"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Setting Up PostgreSQL and Prisma Accelerate
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Set Up a PostgreSQL Database&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Choose a Provider: You can set up PostgreSQL locally or through a managed provider like &lt;strong&gt;Supabase&lt;/strong&gt;, &lt;strong&gt;Railway&lt;/strong&gt;, &lt;strong&gt;Heroku&lt;/strong&gt;, or &lt;strong&gt;Neon&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Get the Database URL: Once the database is set up, you’ll receive a connection string (URL) for PostgreSQL.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Configure Prisma Data Proxy for Prisma Accelerate&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Prisma Accelerate requires the Prisma Data Proxy to enable caching and connection pooling.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Go to &lt;a href="https://cloud.prisma.io/" rel="noopener noreferrer"&gt;Prisma’s Data Platform&lt;/a&gt; and create an account.&lt;br&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%2Ff5ef8clu2rz1dkcqzf3n.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%2Ff5ef8clu2rz1dkcqzf3n.jpg" alt="Sign up for Prisma Data Proxy" width="800" height="856"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once you create a data proxy account either with GitHub or Google account, we will choose the &lt;strong&gt;Accelerate Option&lt;/strong&gt;, remember we already have a database.&lt;/p&gt;&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%2Faeojzfc8icv3s7fswubr.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%2Faeojzfc8icv3s7fswubr.jpg" alt="Select accelerate" width="800" height="461"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select &lt;code&gt;Accelerate&lt;/code&gt;, and provide your database URL and region. Once you provide this, click &lt;code&gt;Enable Accelerate&lt;/code&gt;.&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%2Fpxzspa51vblm5d4zg1lt.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%2Fpxzspa51vblm5d4zg1lt.jpg" alt="Provide database URL &amp;amp; Region" width="800" height="428"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You’ll receive a connection URL for the Data Proxy, as shown in the image below. &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%2Fxrivdhiu8d0wwqx6kna6.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%2Fxrivdhiu8d0wwqx6kna6.jpg" alt="Successful connection" width="800" height="487"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Update the &lt;code&gt;.env&lt;/code&gt; File with the Data Proxy URL:
In the root of your project, add or update the &lt;code&gt;DATABASE_URL&lt;/code&gt; in the &lt;code&gt;.env&lt;/code&gt; file with the Data Proxy URL. This will allow Prisma to use caching and connection pooling.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   DATABASE_URL="prisma://&amp;lt;your-data-proxy-connection-url&amp;gt;"
   DIRECT_DATABASE_URL="&amp;lt;your-postgres-database-connection-url&amp;gt;"
   API_KEY="&amp;lt;Prisma-api-key&amp;gt;"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you have stored the configurations, click &lt;code&gt;I have securely stored my configuration&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Install Prisma Dependencies&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install Prisma, Prisma Client and set up the Prisma schema.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install prisma @prisma/client@latest @prisma/extension-accelerate

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Initialize Prisma to create a prisma/schema.prisma file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx prisma init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The schema should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: &lt;br&gt;
If you’re using a managed database provider that supports connection pooling (e.g., Supabase, Neon, or PlanetScale), you may need to configure two URLs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pooled Connection URL (for runtime)&lt;/strong&gt;: This URL is optimized for production use, where connection pooling is handled by the database provider and this is the &lt;code&gt;DATABASE_URL&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Direct Connection URL (for schema migrations and CLI commands)&lt;/strong&gt;: This direct URL bypasses connection pooling, allowing Prisma CLI commands (like migrations) to work without compatibility issues and this is the &lt;code&gt;DIRECT_DATABASE_URL&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, update schema.prisma to Use directUrl for CLI Commands for migrations or schema updates.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
  directUrl  = env("DIRECT_DATABASE_URL")
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Define CMS Data Models
In the schema.prisma file, define the models for User, Post, and Category. These represent users, content, and categories in the CMS.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;model User {
  id    Int    @id @default(autoincrement())
  name  String
  email String @unique
  posts Post[]
}

model Post {
  id        Int    @id @default(autoincrement())
  title     String
  content   String
  category  Category @relation(fields: [categoryId], references: [id])
  categoryId Int
  author    User   @relation(fields: [authorId], references: [id])
  authorId  Int
  createdAt DateTime @default(now())
}

model Category {
  id    Int    @id @default(autoincrement())
  name  String
  posts Post[]
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Run Migrations to Apply Models to the Database
Run migrations so Prisma applies these models to your PostgreSQL database.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx prisma migrate dev --name init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once it successfully runs, we see the update on the migrations created in the prisma/migrations folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The following migration(s) have been created and applied to new schema changes:

migrations/
  └─ 20241106145324_init/
    └─ migration.sql

Your database is now in sync with your schema.

✔ Generated Prisma Client (v5.22.0) to ./node_modules/@prisma/client in 56ms

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above should be similar to what you see in your terminal.&lt;/p&gt;




&lt;h2&gt;
  
  
  Building CMS Functionality with Prisma and Next.js
&lt;/h2&gt;

&lt;p&gt;With our Next.js and Prisma Accelerate setup in place, it’s time to create the core functionality of our CMS. We’ll focus on initializing the Prisma Client, setting up API routes and pages for managing posts, categories, and authors, and using Prisma Accelerate to optimize data fetching for high performance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Initialize the Prisma Client&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To interact with the database in our Next.js project, we need to initialize the Prisma client. We’ll create a reusable Prisma client instance that can be imported anywhere in the app.&lt;/p&gt;

&lt;p&gt;In the project root, create a folder named src/lib, and add a file called prisma.ts. Inside this file, initialize and export the Prisma client:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// src/lib/prisma.ts
import { PrismaClient } from '@prisma/client/edge';
import { withAccelerate } from '@prisma/extension-accelerate';

const prisma = new PrismaClient().$extends(withAccelerate());

export default prisma;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This setup creates a single instance of the Prisma client, which will be used for all database operations, ensuring efficient and consistent database access across the application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project Structure Overview&lt;/strong&gt;&lt;br&gt;
Now that we have Prisma set up, here’s an overview of the project structure so far:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;prisma-accelerate-cms/
├── app/                        # Next.js pages and API endpoints
│   ├── api/                    # API routes for CRUD operations
│   ├── posts/                  # Static and dynamic pages for posts
│   └── layout.tsx              # Layout file
├── src/
│   ├── lib/
│   │   └── prisma.ts           # Prisma client configuration
├── prisma/                     # Prisma configuration and migrations
│   ├── schema.prisma           # Prisma schema with model definitions
│   └── migrations/             # Migration files
├── .env                        # Environment variables
└── package.json                # Project dependencies
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Building API Routes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With the Prisma client set up, we’re ready to build the API routes for creating and fetching data in our CMS. In the next section, we’ll define API routes for User, Post, and Category models, leveraging Prisma’s data operations to interact with our PostgreSQL database.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create User API Route&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Create an &lt;code&gt;api/users/route.js&lt;/code&gt; folder in the app folder. Set up a POST endpoint to add new and fetch new users in app/api/users/route.js.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import prisma from '../../../src/lib/prisma';

// POST method to create a user
export async function POST(req) {
  const data = await req.json();
  const user = await prisma.user.create({
    data: {
      name: data.name,
      email: data.email,
    },
  });
  return new Response(JSON.stringify(user), {
    headers: { 'Content-Type': 'application/json' },
    status: 201,
  });
}

// GET method to retrieve all users
export async function GET() {
  const users = await prisma.user.findMany();
  return new Response(JSON.stringify(users), {
    headers: { 'Content-Type': 'application/json' },
  });
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This single file handles both the creation and retrieval of users. The POST method adds new users, while the GET method retrieves all users.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create Category API Route
Define a route to create categories in app/api/categories/route.js.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import prisma from '../../../src/lib/prisma';

// POST method to create a category
export async function POST(req) {
  const data = await req.json();
  const category = await prisma.category.create({
    data: {
      name: data.name,
    },
  });
  return new Response(JSON.stringify(category), {
    headers: { 'Content-Type': 'application/json' },
    status: 201,
  });
}

// GET method to retrieve all categories
export async function GET() {
  const categories = await prisma.category.findMany();
  return new Response(JSON.stringify(categories), {
    headers: { 'Content-Type': 'application/json' },
  });
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Create Posts API Route
For the Posts endpoint, we’ll use Prisma Accelerate’s caching to improve data retrieval efficiency.
We will define a POST and GET Method to create and fetch All Posts with Prisma Accelerate.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import prisma from '../../../src/lib/prisma';

// POST method to create a post
export async function POST(req) {
  const data = await req.json();
  const post = await prisma.post.create({
    data: {
      title: data.title,
      content: data.content,
      authorId: data.authorId,
      categoryId: data.categoryId,
    },
  });
  return new Response(JSON.stringify(post), {
    headers: { 'Content-Type': 'application/json' },
    status: 201,
  });
}

// GET method to retrieve all posts with Prisma Accelerate caching
export async function GET(req) {
  const posts = await prisma.post.findMany({
    include: { author: true, category: true },
    cacheStrategy: { ttl: 3600 } // Cache results for 1 hour
  });
  return new Response(JSON.stringify(posts), {
    headers: { 'Content-Type': 'application/json' },
  });
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The cacheStrategy option allows you to control the caching behavior of specific queries. By setting a ttl (time-to-live) value, you define how long a cached response should remain valid before being refreshed from the origin database as it minimizes repeated database calls, thus reducing latency and server load.&lt;/p&gt;

&lt;p&gt;This is particularly beneficial for high-traffic CMS applications, where quick access to content without frequent database hits improves both performance and user experience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Building a Posts UI in Next.js&lt;/strong&gt;&lt;br&gt;
With Prisma Accelerate and our API routes set up, let's create a simple UI in Next.js to display the posts from our CMS. This will give us a practical view of how cached data improves the user experience in the front end, allowing us to measure the impact of Prisma Accelerate on page load times.&lt;/p&gt;

&lt;p&gt;Add a new PostsPage component in your Next.js project to fetch and display posts from the database. This component will use Next.js's Client Component mode since it leverages React’s useEffect and useState hooks to fetch data when the page loads.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// app/posts/page.js
"use client";

import { useEffect, useState } from 'react';

export default function PostsPage() {
  const [posts, setPosts] = useState([]);

  useEffect(() =&amp;gt; {
    async function fetchPosts() {
      try {
        const response = await fetch('/api/posts');
        if (response.ok) {
          const data = await response.json();
          setPosts(data);
        } else {
          console.error("Failed to fetch posts:", response.status);
        }
      } catch (error) {
        console.error("Error fetching posts:", error);
      }
    }

    fetchPosts();
  }, []);

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;Posts&amp;lt;/h1&amp;gt;
      &amp;lt;ul&amp;gt;
        {posts.map((post) =&amp;gt; (
          &amp;lt;li key={post.id}&amp;gt;
            &amp;lt;h2&amp;gt;{post.title}&amp;lt;/h2&amp;gt;
            &amp;lt;p&amp;gt;{post.content}&amp;lt;/p&amp;gt;
          &amp;lt;/li&amp;gt;
        ))}
      &amp;lt;/ul&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It fetches post data from the &lt;code&gt;http://localhost:3000/api/posts&lt;/code&gt;endpoint using fetch.&lt;/p&gt;




&lt;h2&gt;
  
  
  Benchmarking Prisma Accelerate
&lt;/h2&gt;

&lt;p&gt;With the UI in place, we’re ready to benchmark Prisma Accelerate. We’ll conduct tests on three types of fetches: an initial fetch, a cached fetch, and a repeated fetch. To see measurable differences, we’ve seeded our database with multiple posts, simulating a realistic content environment.&lt;/p&gt;

&lt;p&gt;By increasing the data volume, we simulated a more realistic CMS environment, which allowed Prisma Accelerate’s caching to significantly impact response times. Here's how to seed the database and why it matters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step-by-Step: Seeding the Database&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create Seed Script: In the prisma folder, create a file named seed.js to define the sample data.&lt;/li&gt;
&lt;li&gt;Run the Seed Script: Execute the script to populate your database.
Here’s a sample seed.js script to add multiple posts, categories, and users:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// prisma/seed.js
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();

async function main() {
  // Creating sample users
  const user = await prisma.user.create({
    data: { name: "Dinma Jane", email: "dinma@gmail.com" },
  });

  // Creating sample categories
  const category = await prisma.category.create({
    data: { name: "Technology" },
  });

  // Creating multiple posts
  for (let i = 0; i &amp;lt; 1000; i++) {
    await prisma.post.create({
      data: {
        title: `Sample Post ${i + 1}`,
        content: `This is the content of post ${i + 1}`,
        authorId: user.id,
        categoryId: category.id,
      },
    });
  }
}

main()
  .catch((e) =&amp;gt; console.error(e))
  .finally(async () =&amp;gt; {
    await prisma.$disconnect();
  });

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To execute the seed file and populate the database run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node prisma/seed.js

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This script will create:&lt;/p&gt;

&lt;p&gt;One user (Dinma Jane) serves as the author of all posts.&lt;br&gt;
One category (Technology).&lt;br&gt;
1,000 posts, each linked to the same user and category. To make it more realistic, we generated 7000 records. &lt;/p&gt;

&lt;p&gt;All the codes can be found in this &lt;a href="https://github.com/DinmaOtutu/high-perform-cms" rel="noopener noreferrer"&gt;repository&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Updated Benchmark Results
&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%2Fc0gulj0vbxyt2eoh61fm.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%2Fc0gulj0vbxyt2eoh61fm.jpg" alt="Cache vs Origin" width="800" height="433"&gt;&lt;/a&gt;                         |&lt;/p&gt;

&lt;p&gt;Based on the screenshot provided above(Query latency distribution), here’s a breakdown of the performance metrics for Prisma Accelerate with caching enabled:&lt;/p&gt;

&lt;p&gt;Initial Fetch (No Cache): This is the first query hitting the database directly without a cache.&lt;/p&gt;

&lt;p&gt;The average latency for origin queries (served from the database, without cache) is around 263.84 ms.&lt;/p&gt;

&lt;p&gt;Cached Fetch: After the initial query, the data is stored in the cache. Subsequent requests should be faster due to caching.&lt;/p&gt;

&lt;p&gt;The average latency for cached queries is around 30.56 ms.&lt;/p&gt;

&lt;p&gt;Repeated Fetch: This would be similar to the cached fetch if you run it multiple times, as the data is already cached. The cache hit rate is around 81.82%, indicating most queries are served from the cache.&lt;/p&gt;

&lt;p&gt;With the seeded data, here’s an updated comparison of response times:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Test Scenario&lt;/th&gt;
&lt;th&gt;Direct Database Access (No Cache)&lt;/th&gt;
&lt;th&gt;Prisma Accelerate (Caching Enabled)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Initial Fetch (No Cache)&lt;/td&gt;
&lt;td&gt;~263.84 ms&lt;/td&gt;
&lt;td&gt;~263.84 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cached Fetch&lt;/td&gt;
&lt;td&gt;N/A&lt;/td&gt;
&lt;td&gt;~30.56 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Repeated Fetch&lt;/td&gt;
&lt;td&gt;N/A&lt;/td&gt;
&lt;td&gt;~30.56 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




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

&lt;p&gt;We explored how to set up a high-performance CMS using Next.js and Prisma Accelerate. By leveraging Prisma’s cacheStrategy and caching mechanisms, we were able to dramatically improve query response times, with cached queries returning data nearly 10 times faster than those directly accessing the database. This speed boost is particularly advantageous in CMS applications, where users expect quick access to content and smooth, responsive navigation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Takeaways
&lt;/h3&gt;

&lt;p&gt;Efficient Database Access: Prisma Accelerate’s caching and connection pooling reduce database load, allowing frequently accessed data to be served directly from the cache.&lt;/p&gt;

&lt;p&gt;Improved User Experience: Using Prisma Accelerate with Next.js enables us to build a CMS that’s not only fast but also scalable, making it ideal for dynamic applications with heavy read requirements.&lt;/p&gt;

&lt;p&gt;Easy Caching Configuration: The cacheStrategy option provides fine-grained control over caching, allowing developers to configure cache duration based on content freshness needs.&lt;/p&gt;

&lt;p&gt;By integrating Prisma Accelerate into your Next.js applications, you can build a CMS that meets high-performance demands while maintaining scalability. Try adding caching configurations in your projects, and see how Prisma Accelerate transforms your application's performance.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Git 101: An Extensive Beginner's Guide to Version Control</title>
      <dc:creator>DinmaOtutu</dc:creator>
      <pubDate>Tue, 05 Sep 2023 07:06:58 +0000</pubDate>
      <link>https://dev.to/dinmaotutu/git-101-an-extensive-beginners-guide-to-version-control-2m0p</link>
      <guid>https://dev.to/dinmaotutu/git-101-an-extensive-beginners-guide-to-version-control-2m0p</guid>
      <description>&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;What is Version Control?&lt;/li&gt;
&lt;li&gt;Types of Version Control Systems&lt;/li&gt;
&lt;li&gt;Why Git?&lt;/li&gt;
&lt;li&gt;Installing Git&lt;/li&gt;
&lt;li&gt;Configuring Git&lt;/li&gt;
&lt;li&gt;Basic Git Commands&lt;/li&gt;
&lt;li&gt;Git Workflow&lt;/li&gt;
&lt;li&gt;Branching and Merging&lt;/li&gt;
&lt;li&gt;Advanced Features&lt;/li&gt;
&lt;li&gt;Collaboration with Git&lt;/li&gt;
&lt;li&gt;Git GUI Clients&lt;/li&gt;
&lt;li&gt;Best Practices&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;li&gt;Further Reading&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Introduction &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Software development is an intricate process that involves various stages like planning, coding, testing, and deployment. One essential tool that developers use to streamline and manage this process is a Version Control System (VCS). This beginner's guide aims to introduce you to Git, one of the most popular VCS, and help you get started with it, starting from the basics and delving into advanced features.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Version Control? &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Version control is a system that allows multiple people to work on different parts of a project at the same time. A VCS records changes to files and helps you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keep track of changes made to code.&lt;/li&gt;
&lt;li&gt;Revert to previous versions of code.&lt;/li&gt;
&lt;li&gt;Work on different features simultaneously without conflicts.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Types of Version Control Systems &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;There are primarily three types of VCS:&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Local Version Control Systems
&lt;/h4&gt;

&lt;p&gt;In this system, all changes are stored locally on your computer.&lt;/p&gt;

&lt;p&gt;Example: RCS (Revision Control System)&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Centralized Version Control Systems (CVCS)
&lt;/h4&gt;

&lt;p&gt;These systems involve a single, centralized repository. Every user gets their own working copy, but there is only one central repository that stores all the changes.&lt;/p&gt;

&lt;p&gt;Example: SVN (Subversion), CVS (Concurrent Versions System)&lt;/p&gt;

&lt;h4&gt;
  
  
  3. Distributed Version Control Systems (DVCS)
&lt;/h4&gt;

&lt;p&gt;In DVCS, every user has a complete copy of the repository, making it possible to work offline and enabling more flexible workflows.&lt;/p&gt;

&lt;p&gt;Example: Git, Mercurial&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Git? &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Git is an open-source, distributed version control system designed to handle everything from small to large projects with speed and efficiency. Some key features that make Git widely popular are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Speed&lt;/strong&gt;: Git is incredibly fast, which makes it ideal for version control.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Distributed System&lt;/strong&gt;: Every user's working directory is a full-fledged repository, offering a rich history and capability for offline work.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Branching and Merging&lt;/strong&gt;: Git's branching and merging capabilities are better than many VCS.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Strong Community Support&lt;/strong&gt;: Being open-source and popular, it has strong community support.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Installing Git &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Installing Git is relatively simple:&lt;/p&gt;

&lt;h3&gt;
  
  
  For macOS:
&lt;/h3&gt;



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

&lt;/div&gt;



&lt;h3&gt;
  
  
  For Windows:
&lt;/h3&gt;

&lt;p&gt;Download the installer from &lt;a href="https://git-scm.com/download/win" rel="noopener noreferrer"&gt;Git's website&lt;/a&gt; and follow the on-screen instructions.&lt;/p&gt;

&lt;h3&gt;
  
  
  For Linux:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Configuring Git &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Before you start using Git, it's crucial to configure your personal details.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; user.name &lt;span class="s2"&gt;"Your Name"&lt;/span&gt;
git config &lt;span class="nt"&gt;--global&lt;/span&gt; user.email &lt;span class="s2"&gt;"your.email@example.com"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Basic Git Commands &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Here are some basic commands to help you get started:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git init&lt;/code&gt;: Initializes a new Git repository.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git clone [url]&lt;/code&gt;: Clone (or download) a repository.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git add [file-name]&lt;/code&gt;: Add a file to staging.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git commit -m "[commit message]"&lt;/code&gt;: Commit your changes.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git status&lt;/code&gt;: Check the status of your repository.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git pull&lt;/code&gt;: Update your repository&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git push&lt;/code&gt;: Upload your changes to a remote&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Example Usage:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Initialize a Git repository&lt;/span&gt;
git init

&lt;span class="c"&gt;# Add a file&lt;/span&gt;
git add README.md

&lt;span class="c"&gt;# Commit the change&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Initial commit"&lt;/span&gt;

&lt;span class="c"&gt;# Check status&lt;/span&gt;
git status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Git Workflow &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;The Git workflow provides a robust framework that allows multiple developers to collaborate on a project effectively. Below are the standard steps in a typical Git workflow, broken down to help beginners understand the whole process in depth.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Clone or Initialize Repository
&lt;/h3&gt;

&lt;p&gt;Before you can start working on a project, you need to get the source code onto your local machine. You have two primary ways to do this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Clone a Repository&lt;/strong&gt;: If you want to work on an existing project stored in a remote repository, you use the &lt;code&gt;git clone&lt;/code&gt; command to make a copy of the entire repository onto your local machine.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/username/repository.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Initialize a Repository&lt;/strong&gt;: If you are starting a new project from scratch, you'll need to initialize a new repository using &lt;code&gt;git init&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git init
&lt;/code&gt;&lt;/pre&gt;

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

&lt;h3&gt;
  
  
  2. Make Changes
&lt;/h3&gt;

&lt;p&gt;Once you have the codebase on your local machine, you can start making changes to the code. Use your favorite text editor to add new files, modify existing ones, or fix bugs. This is your working directory, and it's isolated from the git repository until you decide to add these changes to the staging area.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Stage Changes
&lt;/h3&gt;

&lt;p&gt;After making changes to your codebase, the next step is to stage those changes for commit. The staging area is like a draft space where you can add changes before finally committing them.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;View Changes&lt;/strong&gt;: You can see what changes are made but not yet staged using &lt;code&gt;git status&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git status
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Add Changes&lt;/strong&gt;: Use &lt;code&gt;git add&lt;/code&gt; to stage changes for commit.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add &amp;lt;specific-file&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

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

&lt;h3&gt;
  
  
  4. Commit Changes
&lt;/h3&gt;

&lt;p&gt;Once the changes are staged, you can now commit them to your local repository. A commit is a snapshot of changes that you want to save.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Commit with a Message&lt;/strong&gt;: Always provide a descriptive message for what the commit contains.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Implemented feature X"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

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

&lt;h3&gt;
  
  
  5. Push or Pull Changes
&lt;/h3&gt;

&lt;p&gt;After committing your changes locally, you need to update the remote repository with your changes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Push&lt;/strong&gt;: To send your committed changes to a remote repository, use &lt;code&gt;git push&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git push origin &amp;lt;branch-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Pull&lt;/strong&gt;: Before you push changes, it’s a good practice to pull the latest changes from the remote repository to ensure everything is up-to-date and to resolve any potential merge conflicts.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git pull origin &amp;lt;branch-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

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

&lt;h2&gt;
  
  
  Branching and Merging &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;One of Git’s most powerful features is its branching capabilities. Branching means diverging from the main line of development to continue work without affecting that main line.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git branch&lt;/code&gt;: List all branches.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git branch [branch-name]&lt;/code&gt;: Create a new branch.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git checkout [branch-name]&lt;/code&gt;: Switch to a branch.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git merge [branch-name]&lt;/code&gt;: Merge a branch into the active branch.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Example Usage:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Create a new branch&lt;/span&gt;
git branch feature-x

&lt;span class="c"&gt;# Switch to the new branch&lt;/span&gt;
git checkout feature-x

&lt;span class="c"&gt;# Make changes and commit them&lt;/span&gt;
git add &lt;span class="nb"&gt;.&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Implement feature x"&lt;/span&gt;

&lt;span class="c"&gt;# Switch back to the main branch&lt;/span&gt;
git checkout main

&lt;span class="c"&gt;# Merge feature-x into main&lt;/span&gt;
git merge feature-x
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Advanced Features &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Stashing
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git stash  &lt;span class="c"&gt;# Store changes temporarily&lt;/span&gt;
git stash apply &lt;span class="c"&gt;# Reapply stored changes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Rebase
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git rebase main &lt;span class="c"&gt;# Apply changes from main onto the current branch&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Tags and Releases
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git tag v1.0 &lt;span class="c"&gt;# Tag the current commit&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Collaboration with Git &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Collaboration is one of the key aspects of software development, and Git offers multiple ways to work with teams and contribute to open-source projects. Let’s dive into some of the methods and practices commonly used in Git for collaboration.&lt;/p&gt;

&lt;h3&gt;
  
  
  Forking
&lt;/h3&gt;

&lt;p&gt;Forking is often used in open-source projects. It allows you to create a personal copy of another user’s repository, where you can make changes without affecting the original project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example Usage&lt;/strong&gt;: To fork a repository on GitHub, click on the "Fork" button at the top-right corner of the repository page.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cloning
&lt;/h3&gt;

&lt;p&gt;After forking a project (or directly from the original project if you have access), you need to clone the repository to download its content to your local machine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example Usage&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/your-username/forked-repository.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Remote
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;remote&lt;/code&gt; command helps you to manage the set of repositories (“remotes”) whose branches you track. Remotes are simply URLs that point to a repository, which you can pull from and push to.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example Usage&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Add a Remote&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git remote add origin https://github.com/your-username/repository.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;List Remotes&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git remote &lt;span class="nt"&gt;-v&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Remove a Remote&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git remote remove origin
&lt;/code&gt;&lt;/pre&gt;

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

&lt;h3&gt;
  
  
  Pull Requests
&lt;/h3&gt;

&lt;p&gt;Pull requests are a way to propose changes for review. After you've pushed a change to a remote repository, you can submit a pull request in the hosting service's interface, like GitHub or GitLab.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example Usage&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Push Your Changes to a Remote Repository&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git push origin feature-branch
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create a Pull Request&lt;/strong&gt;: Open the web interface for the remote repository (e.g., GitHub). Navigate to "Pull Requests" and click "New Pull Request". Choose the branches you want to merge and submit your pull request.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Merge Pull Request&lt;/strong&gt;: Once reviewed, the pull request can be merged into the main codebase.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Git GUI Clients &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;While the command line offers a powerful way to interact with Git, some users prefer using graphical user interfaces (GUIs) for some or all of their Git operations. Here are some popular Git GUI clients:&lt;/p&gt;

&lt;h3&gt;
  
  
  SourceTree
&lt;/h3&gt;

&lt;p&gt;SourceTree offers a rich user interface that allows you to visualize your repositories, making it easier to manage your Git repositories. It is available for both macOS and Windows.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Website&lt;/strong&gt;: &lt;a href="https://www.sourcetreeapp.com/" rel="noopener noreferrer"&gt;SourceTree&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  GitHub Desktop
&lt;/h3&gt;

&lt;p&gt;Developed by GitHub, this application offers seamless integration with the platform. It simplifies complicated Git commands into understandable GUI-based actions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Website&lt;/strong&gt;: &lt;a href="https://desktop.github.com/" rel="noopener noreferrer"&gt;GitHub Desktop&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  GitKraken
&lt;/h3&gt;

&lt;p&gt;GitKraken provides a visually appealing interface, with support for multiple platforms including Windows, macOS, and Linux. It offers integrations with other popular Git hosting services as well.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Website&lt;/strong&gt;: &lt;a href="https://www.gitkraken.com/" rel="noopener noreferrer"&gt;GitKraken&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  TortoiseGit
&lt;/h3&gt;

&lt;p&gt;TortoiseGit is a Windows Shell Interface to Git and is based on TortoiseSVN. It's open-source and integrates into the Windows context menu for easy access.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Website&lt;/strong&gt;: &lt;a href="https://tortoisegit.org/" rel="noopener noreferrer"&gt;TortoiseGit&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Best Practices &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Commit Often, Push Less&lt;/strong&gt;: Frequent commits make it easier to identify issues.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Write Descriptive Commit Messages&lt;/strong&gt;: Helps future-you and others understand changes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Branches&lt;/strong&gt;: Helps isolate features or bug fixes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Always Pull Before Pushing&lt;/strong&gt;: To reduce merge conflicts.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Git is an essential tool for modern software development. From basic operations like commit, pull, and push to advanced features like branching, stashing, and rebasing, Git provides developers with the tools they need to collaborate effectively and maintain a clean and manageable codebase.&lt;/p&gt;

&lt;h2&gt;
  
  
  Further Reading &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://git-scm.com/doc" rel="noopener noreferrer"&gt;Official Git Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://git-scm.com/book/en/v2" rel="noopener noreferrer"&gt;Pro Git Book&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.atlassian.com/git/tutorials" rel="noopener noreferrer"&gt;Atlassian Git Tutorial&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The more you use git, the more comfortable you'll become. Happy coding!&lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
      <category>versioncontrol</category>
      <category>gitforbeginners</category>
    </item>
    <item>
      <title>Unit Testing with Mocha: A Hands-On Tutorial For Beginners</title>
      <dc:creator>DinmaOtutu</dc:creator>
      <pubDate>Mon, 04 Sep 2023 09:34:30 +0000</pubDate>
      <link>https://dev.to/dinmaotutu/unit-testing-with-mocha-a-hands-on-tutorial-1859</link>
      <guid>https://dev.to/dinmaotutu/unit-testing-with-mocha-a-hands-on-tutorial-1859</guid>
      <description>&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;What is Unit Testing?&lt;/li&gt;
&lt;li&gt;Why Mocha?&lt;/li&gt;
&lt;li&gt;Setting Up The Project&lt;/li&gt;
&lt;li&gt;Your First Test with Mocha&lt;/li&gt;
&lt;li&gt;Assertions in Mocha&lt;/li&gt;
&lt;li&gt;Hooks&lt;/li&gt;
&lt;li&gt;Testing Asynchronous Code&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;li&gt;Further Reading&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Introduction &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Testing is an integral part of modern software development practices. Among various types of testing, unit testing is often the first line of defense against bugs and errors. In this tutorial, we will explore how to write unit tests using Mocha, a popular JavaScript testing framework.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Unit Testing? &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Unit testing is the practice of testing the smallest pieces of code, usually individual functions or methods, in isolation from the rest of the codebase. The primary goals are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ensure code behaves as expected under various conditions.&lt;/li&gt;
&lt;li&gt;Make it easier to refactor code.&lt;/li&gt;
&lt;li&gt;Improve the overall design of the code.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why Mocha? &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Mocha is one of the most popular testing libraries for JavaScript and Node.js. Here are a few reasons why developers prefer Mocha:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Flexibility&lt;/strong&gt;: Mocha is unopinionated about assertion libraries and lets you pair it with your choice like Chai, Jasmine, etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rich Feature Set&lt;/strong&gt;: Built-in test runners, test hooks, and reporters.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ease of Use&lt;/strong&gt;: Simple API makes it easy for beginners to pick up.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Setting Up The Project &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Let's begin by setting up a new Node.js project and installing Mocha.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Create a new directory for the project:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;mocha-tutorial
&lt;span class="nb"&gt;cd &lt;/span&gt;mocha-tutorial
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Initialize a new Node.js project:&lt;br&gt;
&lt;/p&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;/li&gt;
&lt;li&gt;
&lt;p&gt;Install Mocha:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save-dev&lt;/span&gt; mocha
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Your First Test with Mocha &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Create a new file named &lt;code&gt;math.js&lt;/code&gt; with the following function to test:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&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;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create another file named &lt;code&gt;test.js&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt; &lt;span class="p"&gt;}&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;./math&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;assert&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;assert&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Math Functions&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;should return 3 when 1 is added to 2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;add&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="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;3&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;/li&gt;
&lt;li&gt;
&lt;p&gt;Update your &lt;code&gt;package.json&lt;/code&gt;:&lt;br&gt;
&lt;/p&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;"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;"mocha test.js"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&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;Run the test:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;test&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If everything is set up correctly, you should see a passing test.&lt;/p&gt;

&lt;h2&gt;
  
  
  Assertions in Mocha &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Mocha itself doesn't come with an assertion library, so you can pair it with any assertion library of your choice. In our example, we used Node's built-in &lt;code&gt;assert&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="nx"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;add&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="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Hooks &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Mocha provides hooks like &lt;code&gt;before()&lt;/code&gt;, &lt;code&gt;after()&lt;/code&gt;, &lt;code&gt;beforeEach()&lt;/code&gt;, and &lt;code&gt;afterEach()&lt;/code&gt; for setup and teardown operations.&lt;/p&gt;

&lt;p&gt;Example:&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="nf"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Math Functions&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;before&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// runs before all tests in this block&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="nf"&gt;after&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// runs after all tests in this block&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="nf"&gt;beforeEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// runs before each test in this block&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="nf"&gt;afterEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// runs after each test in this block&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;h2&gt;
  
  
  Testing Asynchronous Code &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Mocha makes it easy to test asynchronous code. Here's an example using promises:&lt;/p&gt;

&lt;p&gt;Suppose you have an asynchronous &lt;code&gt;addAsync&lt;/code&gt; function:&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;function&lt;/span&gt; &lt;span class="nf"&gt;addAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&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="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&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="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;100&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;addAsync&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can test it like so:&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;addAsync&lt;/span&gt; &lt;span class="p"&gt;}&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;./math&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;assert&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;assert&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Math Functions - Async&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;should return 3 when 1 is added to 2 asynchronously&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&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="nf"&gt;addAsync&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="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&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;h2&gt;
  
  
  Conclusion &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;In this tutorial, we've learned the basics of unit testing with Mocha. We've set up a simple project, written tests, explored assertions, and even delved into asynchronous testing. Mocha is a versatile and powerful framework that makes it easy to write tests for your JavaScript projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Further Reading &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://mochajs.org/" rel="noopener noreferrer"&gt;Mocha Official Docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.chaijs.com/" rel="noopener noreferrer"&gt;Chai Assertion Library&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nodejs.org/api/assert.html" rel="noopener noreferrer"&gt;Node.js Assert API&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope you found this tutorial helpful. Happy testing!&lt;/p&gt;

</description>
      <category>mocha</category>
      <category>testing</category>
      <category>chai</category>
      <category>unittesting</category>
    </item>
  </channel>
</rss>
