<?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>Forem: Nyoman Sunima</title>
    <description>The latest articles on Forem by Nyoman Sunima (@nyomansunima).</description>
    <link>https://forem.com/nyomansunima</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%2F620862%2Fa11a1fcf-825a-45b2-b31d-3b6b2f243166.png</url>
      <title>Forem: Nyoman Sunima</title>
      <link>https://forem.com/nyomansunima</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/nyomansunima"/>
    <language>en</language>
    <item>
      <title>Turn Nest.Js into Serverless with Nitric in a few seconds</title>
      <dc:creator>Nyoman Sunima</dc:creator>
      <pubDate>Sat, 26 Aug 2023 16:15:00 +0000</pubDate>
      <link>https://forem.com/nyomansunima/turn-nestjs-into-serverless-with-nitric-in-a-few-seconds-ag4</link>
      <guid>https://forem.com/nyomansunima/turn-nestjs-into-serverless-with-nitric-in-a-few-seconds-ag4</guid>
      <description>&lt;p&gt;Hi, my name is Nyoman Sunima. Product Designer and full stack developer. Today I want to share with you a new way to become serverless using your Nest.js application in just a few steps and seconds.&lt;/p&gt;

&lt;p&gt;This post will help you create and deploy your serverless backend API easily and without too much effort. Before I jump in, let me tell you about my problems and challenges.&lt;/p&gt;

&lt;h2&gt;
  
  
  Challenges
&lt;/h2&gt;

&lt;p&gt;When I build a normal Express backend API, I need to know too much about cloud infrastructure. First, think about where I should deploy my project. spec of servers, type of server (vpc, instances, containers, or cloud-native).&lt;/p&gt;

&lt;p&gt;Sometimes, when I finish local development, the project never goes live. It's because I need more setup time when deploying the application than the actual time it takes me to code my projects.&lt;/p&gt;

&lt;p&gt;That's why so many people love serverless. Alright, I am not saying that serverless is suitable for all cases. But think again when you are building a microservice or simple project. I think you should consider using serverless.&lt;/p&gt;

&lt;p&gt;When you are building portfolio projects or dummy projects, you will realize that the actual server never becomes free. For example, AWS EC2 will only allow you to run for about 28 days in a month. Then you need to configure so many things before you can deploy it automatically.&lt;/p&gt;

&lt;h2&gt;
  
  
  NestJs and Serverless Challenges
&lt;/h2&gt;

&lt;p&gt;Alright, now you know that serverless is powerful and may match your development case. Now the problem is that the setup of the Nest.js application to become serverless requires much effort.&lt;/p&gt;

&lt;p&gt;If you are using Express, you might not think too much. Just install some dependencies, and you can make it a serverless project. But if you love to use Nest.Js and want to make it serverless, you need to do more than just install dependencies.&lt;/p&gt;

&lt;p&gt;In my case, I have developed a project using Nest.js, which I should then deploy into a serverless project. I need to install serverless, the AWS Lambda adapter, and set the build using Webpack. Then, after that, you will realize that you will get an error when you deploy.&lt;/p&gt;

&lt;p&gt;You need to add another plugin and configure it to make it work properly on AWS Lambda. After you realize that it's going to take half a day to set up your Nest.js project into serverless,&lt;/p&gt;

&lt;p&gt;I faced this issue and think that developing serverless applications requires many adaptations before I can code. Now I've found the solution. it's called &lt;a href="https://nitric.io" rel="noopener noreferrer"&gt;Nitric&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let me explain more about it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's Nitric and why you should use it?
&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%2Ffpx88y222xy3acy292pk.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%2Ffpx88y222xy3acy292pk.png" alt="Nitric" width="800" height="452"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nitric is an application framework that allows you to build serverless applications without too much effort. They want to provide you with a framework that allows you to work closely with the serverless platform and turn it into code.&lt;/p&gt;

&lt;p&gt;Nitric works like Pulumi. They are using Pulumi behind them. But the difference is that they provide you with a general approach to building your application without the need to address specific providers like Amazon or Google.&lt;/p&gt;

&lt;p&gt;So when you need to deploy your application to a different provider or use a custom provider, it's possible. So don't worry about compatibility and vendor lock-in.&lt;/p&gt;

&lt;p&gt;This feature allows you to deploy your application to different providers at the same time. For example, for stagging deployment to GCP, and production deployment to AWS.&lt;/p&gt;

&lt;h3&gt;
  
  
  Benefits
&lt;/h3&gt;

&lt;p&gt;Here are some of the benefits and pros when I using Nitric in the development process.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Focus on writing code without worry and think about infrastructure, providers, and scallability. Nitric handles them all.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Easy to set up and easy to run. Beginning from the first step until the application runs, you just need to run a few commands on the terminal&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Support multi-providers and even custom providers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Support auto-deployment using Github Actions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Local Development Environment allows you to run the application on a local machine without needing to connect to your serverless provider&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Moving providers without changing a single line of code&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Provide almost anything you need to build a backend application, including a database, storage, event-driven messages, and an API.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Nitric also supports HTTP. NOTE: For now, HTTP only supports node.js frameworks like Express, Fastify, Nestjs, and so on.&lt;/p&gt;

&lt;p&gt;I will cover them all in detail later, so stay tuned. Now let's move on to how to work with Nest.Js. For more information on nitric please refer to &lt;a href="https://nitric.io/" rel="noopener noreferrer"&gt;Nitric Official Site&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How do I make Nest.JS serverless?
&lt;/h2&gt;

&lt;p&gt;Nitric provides a new feature called HTTP. It allows you to turn your HTTP server into a serverless one. So without further ado, let's get into it&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;p&gt;Before you can use nitric, you need to install some dependencies and stacks on your local machine, including&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://nitric.io/docs/guides/getting-started" rel="noopener noreferrer"&gt;Nitic Server&lt;/a&gt; - Provide a local server for application development.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.pulumi.com/docs/cli/" rel="noopener noreferrer"&gt;Pulumi CLI&lt;/a&gt; - Nitric using Pulumi to deploy your stacks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://nodejs.org/en/download" rel="noopener noreferrer"&gt;Node.js &amp;amp; npm&lt;/a&gt; - Running Nest.js application&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.docker.com/get-started/" rel="noopener noreferrer"&gt;Docker&lt;/a&gt; Create docker image for project&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://git-scm.com/" rel="noopener noreferrer"&gt;Git&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Local Development: Nest.js using nitric
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Start by creating a new nest project by running&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx @nestjs/cli new nitric-nestjs
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;It will create a new NestJS project called Nitric-NestJS. Follow the instructions, then open it in your code editor.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Install the Nitric SDK&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i @nitric/sdk
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Open the main file, and then you will find the bootstrap function. All you need to do is just remove the port, and then make the application run on the specified port from the argument passed to the bootstrap function.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;
&lt;span class="cm"&gt;/**
 * Initialize the application and starts listening on the specified port.
 *
 * @param {number} port - The port number to listen on.
 * @return {Promise&amp;lt;void&amp;gt;} - A promise that resolves when the application is successfully started.
 */&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;bootstrap&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="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&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;NestFactory&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="nx"&gt;AppModule&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;useGlobalPipes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ValidationPipe&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;transform&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="na"&gt;whitelist&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="na"&gt;forbidNonWhitelisted&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;transformOptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;enableImplicitConversion&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="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;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="nf"&gt;compression&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
  &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;helmet&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
  &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enableCors&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="s1"&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="c1"&gt;// listen on a provided port from nitric&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Now all you need to do is import the &lt;code&gt;http\&lt;/code&gt; from '@nitric/sdk', then pass the bootstrap function.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;http&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="s1"&gt;@nitric/sdk&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="c1"&gt;// the code before&lt;/span&gt;

&lt;span class="c1"&gt;// this will transform your application&lt;/span&gt;
&lt;span class="c1"&gt;// into serverless with adapter&lt;/span&gt;
&lt;span class="nf"&gt;http&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bootstrap&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;Alright, now everything is fine. All you need to do is start the nitric server by running&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nitric start
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;then run the Nest.Js application on development mode using&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;The command above will start the Nitric server on your local machine and also start the development for Nest.Js. Now you can enjoy coding.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;!optional if you are not comfortable with the command and want to execute it on a single line of code. All you need to do is install it concurrently by running&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i &lt;span class="nt"&gt;-D&lt;/span&gt; concurrently
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Then all you need to do is change the scripts on your "package.json" into&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="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;your&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;other&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;secrets&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="nl"&gt;"dev"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"concurrently &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;nitric start&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;nest start --watch&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Now it's done.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Start the application by running &lt;code&gt;npm run dev\&lt;/code&gt;. Now you can see the results&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%2Fbsbhebwyvmfa94lqd0x4.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%2Fbsbhebwyvmfa94lqd0x4.png" alt="Development" width="800" height="522"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Deploy Application to the cloud provider
&lt;/h3&gt;

&lt;p&gt;To deploy your serverless application to a serverless provider like Google or Amazon Web Services, you need a few commands to set up and deploy.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Create a new stack for deployment by running this command&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nitric stack new
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;This command will ask you about the stack name. let's just call it "staging". Then it will move to choose the provider, for now, let's use GCP. You may ask for some information. Just fill it out with your preferences.&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%2Fb93bwn027rte43mhzu38.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%2Fb93bwn027rte43mhzu38.png" alt="Result" width="800" height="522"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Now, after finishing, it will create a new file called "nitric-staging.yaml". And the inside looks like this.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;staging&lt;/span&gt;
&lt;span class="na"&gt;provider&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nitric/gcp@0.32.0&lt;/span&gt;
&lt;span class="na"&gt;gcp-project-id&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;test&lt;/span&gt;
&lt;span class="na"&gt;region&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;us-east1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To deploy, please ensure you have already installed the prerequisites and logged into your Pulumi account. Then run the following command:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;nitric up -s staging -v0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;This command will create a Docker image and configure your GCP account to be ready. After the deployment finishes, you will see the URL. If not, you can login to pulumi account and then find the resource URL&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;What do you think? Have you tried it? It looks easy, right? In my opinion, I would prefer to use Nitric to make my application serverless. Rather than other frameworks like serverless, which need to be configured too much to just deploy a single function,&lt;/p&gt;

&lt;p&gt;If you have any questions or anything related to this article, Please let me know in the comment section. Don't forget to like it if it's useful.&lt;/p&gt;

&lt;p&gt;Looking for collaboration or projects? Please let me know. I would be glad to hear about your problem.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How to make your GitHub project better</title>
      <dc:creator>Nyoman Sunima</dc:creator>
      <pubDate>Mon, 05 Jun 2023 07:15:53 +0000</pubDate>
      <link>https://forem.com/nyomansunima/how-to-make-your-github-project-better-51ph</link>
      <guid>https://forem.com/nyomansunima/how-to-make-your-github-project-better-51ph</guid>
      <description>&lt;p&gt;Hi, welcome. Today, I just want to share my experience using GitHub and how I set it up for the project. This article may be interesting for beginners who need to set up their projects to become more professional and enhance their workflows.&lt;/p&gt;

&lt;p&gt;Ok, without further ado, let's get into it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add better README
&lt;/h2&gt;

&lt;p&gt;The first one I consider to be set up is to create a fantastic and useful README. The README should contain all information about the project, including background, motivation, process, features, and acknowledgment.&lt;/p&gt;

&lt;p&gt;Also, some READMEs can contain the guide, instructions, roadmaps, license, and credits. Of course, if you have just a simple project, what you should include is a description and some acknowledgment, including the stack and features.&lt;/p&gt;

&lt;p&gt;I have written an article before about &lt;a href="https://nyomansunima.hashnode.dev/how-to-create-a-better-readme" rel="noopener noreferrer"&gt;Creeate a better README&lt;/a&gt;. If you want more detail, please read the article.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create License
&lt;/h2&gt;

&lt;p&gt;Now let's move into the license section. If your project is an open-source project, you should have a license to protect your work. Most of the general public can choose MIT or GPL. If you are still confused about what license should pick for your project please refer to &lt;a href="https://choosealicense.com/" rel="noopener noreferrer"&gt;https://choosealicense.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Creating a license on GitHub has now become easy. I will give you an example of how to create an MIT license in just a few seconds.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;First, move into your GitHub project. then start creating a new file named "&lt;strong&gt;LICENSE.&lt;/strong&gt; Now you can see a visible button "Choose a license template" in the header of the file name. You can click and start picking out some templates.&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%2Fkpqgrzo7bzlissi11c3z.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%2Fkpqgrzo7bzlissi11c3z.png" alt="License" width="800" height="498"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Now you can pick the license using MIT. Then fill in some required information, including the year and full name. You can also see what the differences are between the licenses, like permissions, limitations, and conditions.&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%2Fbbbwibpus6pwnokyp7j5.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%2Fbbbwibpus6pwnokyp7j5.png" alt="License" width="800" height="498"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now you have a better license for your project, which can be pretty quick.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Add contributing
&lt;/h2&gt;

&lt;p&gt;Now, let's set up a document to let other contributors know what they should do to contribute to your project. This document is very important to other people if they want to contribute and make changes to your code. I made this document straightforward. Here are some details that can be included in the document:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Getting started&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Requirements&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pull Request&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Issues and feature requests&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Security&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Testing&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Code of conduct&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here are some references that can help you&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/PostHog/posthog/blob/master/CONTRIBUTING.md" rel="noopener noreferrer"&gt;https://github.com/PostHog/posthog/blob/master/CONTRIBUTING.md&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/openwrt/packages/blob/master/CONTRIBUTING.md" rel="noopener noreferrer"&gt;https://github.com/openwrt/packages/blob/master/CONTRIBUTING.md&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Changelog
&lt;/h2&gt;

&lt;p&gt;A changelog is used to log all activity when you release new tags, fix bugs, or add features to your release. You can document your app with the tags, then create a record to let others know what changes you make in each release.&lt;/p&gt;

&lt;p&gt;Inside the changelog can contain some information&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Tags (Versions)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Update&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Bug Fixed&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Feature added&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%2F0ajup2mdglu704z78sns.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%2F0ajup2mdglu704z78sns.png" alt="Changelog" width="800" height="498"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Code of conduct
&lt;/h2&gt;

&lt;p&gt;Start coding as soon as possible. A code of conduct helps you and the community specify standards, behaviors, and some rules that can protect all members of the community from unexpected behavior that can drain your work.&lt;/p&gt;

&lt;p&gt;This document is pretty important, you may need it as soon as the project is created. If you need some questions and need to know what exactly this feature is, you can this post about the &lt;a href="https://opensource.guide/code-of-conduct/" rel="noopener noreferrer"&gt;Code of Conduct&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To create a code of conduct on GitHub, you can simply create it using a template.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Go add a new file called "CODE_OF_CONDUCT.md"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Start by clicking "Choose a Code of Conduct Template"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Modify and save&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%2F0flwb9zdujt3tv575tkb.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%2F0flwb9zdujt3tv575tkb.png" alt="Code of conduct" width="800" height="498"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Branch protection rule
&lt;/h2&gt;

&lt;p&gt;If you work with multiple branches and collaborate with many contributors, I prefer to use a branch protection rule. This can help you protect your branch by using a rule that can help you reduce some actions and commits that have unexpected results.&lt;/p&gt;

&lt;p&gt;In my experience, I will create a default branch as the main and protect it. So we can't force a push to the branch, all we can do is merge that. You can also add some features like&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Require checks before the merge&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Require pull request before the merge&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Lock branch&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;and event signed commits&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To start protecting your branch, go ahead into "Settings", then move into "Branches.". Now you can create one. Here are example&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%2Frcakyj9vygcu1znqgv2a.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%2Frcakyj9vygcu1znqgv2a.png" alt="Brach protection rule" width="800" height="498"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Socials preview
&lt;/h2&gt;

&lt;p&gt;Social previewing can't be important, but this enables you to make your project more confident when sharing it with the community on social media sites like Twitter, Facebook, and others.&lt;/p&gt;

&lt;p&gt;Social media doesn't impact your workflow as much, however, in my opinion, adding social media can give you more value and make you look more serious. If you want to add your preview, please head to "General" and then move into the "Social Preview" section.&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%2Fun0rrmzed3m81z5ek1i1.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%2Fun0rrmzed3m81z5ek1i1.png" alt="Social preview" width="800" height="490"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Issues template
&lt;/h2&gt;

&lt;p&gt;Do you realize that we get bored doing the same things repeatedly? That's why I use a template to create an issue. Templates not only help you save the most time but also give you some boilerplate to create an issue. So the user who wants to report a bug or feature request can have some form to fill out.&lt;/p&gt;

&lt;p&gt;I personally at least need two types of issue templates: bug &lt;strong&gt;reports&lt;/strong&gt; and &lt;strong&gt;feature requests.&lt;/strong&gt; You can create as much as you want, for example, a security report or other things.&lt;/p&gt;

&lt;p&gt;To create your template, you can easily set it up using GitHub. Just go to Settings &amp;gt; General. In the feature section, you can see a template section. You can create your own.&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%2F570jvb183546xp0nougq.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%2F570jvb183546xp0nougq.png" alt="Issue Template" width="800" height="326"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2soepj2fbjhm4im8em9s.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%2F2soepj2fbjhm4im8em9s.png" alt="Issue Template" width="800" height="326"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, if you want to create issues, you will be redirected to the template page and guided to use the form.&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%2Fffxcuw6m61p3py8zdpn7.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%2Fffxcuw6m61p3py8zdpn7.png" alt="Issue Template" width="800" height="522"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you choose bug report, you can see an awesome template you can use to make your life easier.&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%2Fjw6wdq2yo25vgdxt52dq.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%2Fjw6wdq2yo25vgdxt52dq.png" alt="Issue template" width="800" height="522"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Pull request template
&lt;/h2&gt;

&lt;p&gt;Pull requests are another one. This feature is the same as the Issues template but works for pull requests. The function is mainly the same, however, pull requests are created under the Markdown file.&lt;/p&gt;

&lt;p&gt;To create your pull request template. You can create a new file called &lt;strong&gt;pull_request_template.md&lt;/strong&gt; inside the github folder. For more reference, you can see the documentation in &lt;a href="https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/creating-a-pull-request-template-for-your-repository" rel="noopener noreferrer"&gt;Create PR Template Guide&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu6s1jv0phsey57ab7340.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%2Fu6s1jv0phsey57ab7340.png" alt="PR Template" width="800" height="522"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Sponsorship
&lt;/h2&gt;

&lt;p&gt;If your project looks interesting and has an impact on other people, you can ask for donations from other people to help you maintain the project by using sponsors. You can gain some sponsors by using some platforms including&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Ko-fi&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Github Sponsors&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open Collective&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Patreon&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;and others&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This sponsor works for your personal profile or Github organization. If you prefer to use Github Sponsor, you need to setup your account under &lt;a href="https://github.com/sponsors/" rel="noopener noreferrer"&gt;https://github.com/sponsors/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How to use this money depends on your needs. You can use the money to buy hosting, domains, paid services, integrations, and even some cash for your hard work.&lt;/p&gt;

&lt;p&gt;To setup, you can go into Settings -&amp;gt; General and under Sponsorship&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%2F9tyi8riede2n2xnpozr7.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%2F9tyi8riede2n2xnpozr7.png" alt="Sponsorship" width="800" height="202"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxnp0sdnv9lxs561bu9tp.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%2Fxnp0sdnv9lxs561bu9tp.png" alt="Sponsorship" width="800" height="522"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Discussion
&lt;/h2&gt;

&lt;p&gt;You have so many participants, users, and contributors. I will set up the discussion. This will enable communication between the user and the participant. How about issues? Well, you can also use the same feature in an issue to discuss and communicate.&lt;/p&gt;

&lt;p&gt;However, I use issues to communicate technical information and fix problems, on the other side, discussions are used to create announcements and polls and collect and discuss ideas.&lt;/p&gt;

&lt;p&gt;You can setup and enable discussion under "General" settings.&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%2Fxue5b0t19065u5f02hoi.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%2Fxue5b0t19065u5f02hoi.png" alt="Discussion" width="800" height="83"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, you can see the discussion tab in the top menu of your project and start creating your discussion with your user.&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%2Fc1ctxvi99hb5tajd11z6.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%2Fc1ctxvi99hb5tajd11z6.png" alt="Discussion" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Projects as project management
&lt;/h2&gt;

&lt;p&gt;Now, move on to how to manage my tasks on GitHub. I love this feature a lot. So when I start creating a blank project with my client, I will prefer to use GitHub projects. Not just about including projects in one platform, projects can help me move faster with my development workflows.&lt;/p&gt;

&lt;p&gt;All teams can communicate with each other, including designers, developers, and testers, in one place. I never say that you don't need another project manager. But, in my opinion, projects are far enough away to use with your team.&lt;/p&gt;

&lt;p&gt;All features, including tasks (as issues), drafts, goals as milestones, roadmaps, and so on. However, one thing missing from projects is the reminder of tasks. You can also manage your multiple repos in a single project. So if you separate your project into different repositories, you are still able to communicate with each other.&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%2F8pg76io3aqt533iq17wm.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%2F8pg76io3aqt533iq17wm.png" alt="Projects" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Automatic delete head branch
&lt;/h2&gt;

&lt;p&gt;This feature kind of helps you a lot with multi-branches. How do you manage your branch on GitHub? using the feature approach or the environment approach (dev, staging, and production)? I love the feature approach. If you are working with a team and each team has its job, the feature approach can help you.&lt;/p&gt;

&lt;p&gt;You will create a branch for each feature you develop. eg, "signin". Now that the feature is ready, you can start to merge the code. Before we jump, you better do a pull request and then assign a tester or reviewer to review your code. So we can create the best quality code.&lt;/p&gt;

&lt;p&gt;If the feature is acceptable, you can merge it into the main branch, which will automatically delete your current branch.&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%2Fcrg7m9hlsu94q1qq2pbg.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%2Fcrg7m9hlsu94q1qq2pbg.png" alt="Delete head branch" width="800" height="122"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Go ahead and enable it in the general settings.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code security and analysis
&lt;/h2&gt;

&lt;p&gt;This feature helps you keep your repository code updated and secure. You will grant permission for GitHub to do read-only analysis to check your code. There are several points&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Vulnerability reporting&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dependency graph&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dependabot&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Code scanning&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Secret scanning&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I enabled all of these features. The ones I love are code scanning and Dependabot. Code scanning will scan your code automatically if you push it. Dependabot will check every dependency in your repository and create a new pull request to merge if an update is found.&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%2F41i3pog6jbt8ors2tiiq.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%2F41i3pog6jbt8ors2tiiq.png" alt="Code security" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Labels &amp;amp; Milestones
&lt;/h2&gt;

&lt;p&gt;Keep the labels that are needed for your project. then start creating a milestone as a target for your next movement. Labels are very useful when you're working with many issues in your repositories. You can filter and manipulate them using labels.&lt;/p&gt;

&lt;p&gt;Keep important labels like bux, fix, enhancement, good first issue, dependencies, and documentation, and add your preferences.&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%2Fstla5a8eche37c7fiyx9.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%2Fstla5a8eche37c7fiyx9.png" alt="Labels" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F292xhu364hajpmtafh70.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%2F292xhu364hajpmtafh70.png" alt="Milestones" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Workflows
&lt;/h2&gt;

&lt;p&gt;Now, let's move into continued development. All we can do is set up actions for our repository. If you don't understanding about action you can read more in &lt;a href="https://github.com/features/actions" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At least you should add this workflows in your actions&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Build&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Linter&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Analysis&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Testing&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Code scanning&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can also use actions to automatically release your app using tags, deploy it, or publish it to a server or Play Store.&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%2Ff2upsac6mem8oamvcmoz.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%2Ff2upsac6mem8oamvcmoz.png" alt="Workflows" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can explore more features on GitHub, I just want to share my experience while using it. If you have any questions or suggestions, you can send me a message on &lt;a href="https://twitter.com/nyomansunima" rel="noopener noreferrer"&gt;twitter&lt;/a&gt;. If there is a misspelled word, please let me know.  &lt;/p&gt;

&lt;p&gt;Thanks. Have a nice day, developer.&lt;/p&gt;

</description>
      <category>github</category>
      <category>tips</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to create better README</title>
      <dc:creator>Nyoman Sunima</dc:creator>
      <pubDate>Sat, 03 Jun 2023 06:35:10 +0000</pubDate>
      <link>https://forem.com/nyomansunima/how-to-create-better-readme-1j0n</link>
      <guid>https://forem.com/nyomansunima/how-to-create-better-readme-1j0n</guid>
      <description>&lt;p&gt;Hi, I am Nyoman Sunima, a product designer and full-stack developer in Bali, Indonesia. In this article, we will discuss and start sharing my experiences while creating a README file for the project on GitHub, GitLab, or Bitbucket. Then we will discuss and share some tips that may help you get inspiration while creating a better README file. Ok, with that said, let's get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why is README so essential?
&lt;/h2&gt;

&lt;p&gt;If you're exploring a public repository, no matter if it's on GitHub or GitLab, you will find so many out there that always have a README file. Why? As the name suggests, this file will be read by another visitor while visiting and contributing to your project.&lt;/p&gt;

&lt;p&gt;So when they navigate to your project, the first thing they will see is the README file. Creating a good README can help your contributors, visitors, and users understand exactly what your project is.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding your target audience
&lt;/h2&gt;

&lt;p&gt;In my experience, when creating a readme, the first thing I should consider is my target audience. No matter how good your project is, if you can't communicate with your users, it will be nothing.&lt;/p&gt;

&lt;p&gt;There are two types of user repositories in general that could use your project.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Technical People&lt;/strong&gt;, Work as an engineer, developer, scientist, or other technical skill.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Non&lt;/strong&gt;-&lt;strong&gt;technical people&lt;/strong&gt; work as marketers, content writers, and others.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If your project is about dependencies, packages, SDKs, APIs, etc., you will need to create a README for technical people. However, if your project is just about sharing files, content, and other things, you may not need technical instructions. So now let's do a deep dive and discuss the main topic in the next part.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding a banner or logo
&lt;/h2&gt;

&lt;p&gt;When I publish my repository to the public, the first thing I need to do is create some icons or a logo for the project. There is no need to be perfect; at least show the project's identity. This can be a logo or banner that is placed at the top of your readme file.&lt;/p&gt;

&lt;p&gt;When I start my readme, I realize that having a banner or logo will make my repository better and more attractive. Below, you can see the difference between using a banner or logo and not.&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%2Fpolnpzlz6wil9s00xjeo.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%2Fpolnpzlz6wil9s00xjeo.png" alt="Using Banner or Logo" width="800" height="442"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmk319onn3sl3v94hshw2.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%2Fmk319onn3sl3v94hshw2.png" alt="Without Banner or logo" width="800" height="442"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now if you take a look at these two READMEs, which one is better? In my opinion, using banners makes them look more attractive and awesome.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add a title
&lt;/h2&gt;

&lt;p&gt;Next is adding the project title. Ensure you give a clear title so the user can easily capture the repo by name. To make something easy, I use the project name or the purpose. For example&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Drillu&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;NestJs API Helper&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To name your project, this depends on your preference or need. So don't think too much about this little name.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add short description
&lt;/h2&gt;

&lt;p&gt;Before beginning to fully let the user know about the short bio for your project, For example, you have a project that contains a library for 'automate post'. You can create a short description from the context. e.g., "powerful and simple automated cross-post in Hashnode, Medium, and dev.to.".&lt;/p&gt;

&lt;p&gt;So the user knows exactly what the project is without needing to read all of the documentation and instructions.&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%2Fzbqm28e2kgqiu6d13xsi.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%2Fzbqm28e2kgqiu6d13xsi.png" alt="Short description" width="772" height="290"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Add badges
&lt;/h2&gt;

&lt;p&gt;Another cool thing I added to my project are status badges. This is not necessarily important, but it can give your audience a little expression about the project status. You can show your code size, build status, test status, and integrations.&lt;/p&gt;

&lt;p&gt;The most important thing is that this feature is updated automatically through your processes, issues, requests, and events. If you're quite interested in adding this feature to your README, please check out &lt;a href="https://shields.io/" rel="noopener noreferrer"&gt;Shield.io&lt;/a&gt; to create your own badges.&lt;/p&gt;

&lt;p&gt;Here is how your project will look when using badges, Look cool, right?&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%2F5cbqbdr55bcuir0dc642.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%2F5cbqbdr55bcuir0dc642.png" alt="Badges" width="800" height="167"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Add important links
&lt;/h2&gt;

&lt;p&gt;Another tip for you is to add some links that are quite important to the user. This can include the demo, issues, status, website, community, roadmap, and feature requests.&lt;/p&gt;

&lt;p&gt;This is kind of helpful for your users to navigate faster. This feature is optional; however, I prefer to add it if there are important links.&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%2Fxx3k51ugly21321ccm73.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%2Fxx3k51ugly21321ccm73.png" alt="Important links" width="800" height="61"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;If your project documentation is very long or sometimes has different sections and nested contents, I prefer to use a table of contents; this can help your reader move faster by just clicking on your navigation menu.&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%2Fxp1ke46yngni056yysrf.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%2Fxp1ke46yngni056yysrf.png" alt="TOC" width="800" height="247"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  About projects
&lt;/h2&gt;

&lt;p&gt;Before starting on another level, I first added a simple description, followed by a strong definition of what the projects are. This is the longer version of the short description. You can add several pieces of information inside the about section, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Backgrounds&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Motivation to create the project&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;What is the project aimed to&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The purpose of projects&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This part is very important, in my opinion. We need to guide the user to understand what the project is before they can use it or contribute to it. Here is an example&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%2Fcn90y7xbz64jr25p5dqd.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%2Fcn90y7xbz64jr25p5dqd.png" alt="About" width="800" height="334"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to get started and run
&lt;/h2&gt;

&lt;p&gt;If your project contains a project that can run on a local machine, you better add instructions about how to get started with this project. This can include points like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Requirements - Before started what, what stack or dependencies should be installed&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Instructions - Step by step to running the application locally&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Note - Some important information when starting the app on the local machine&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This section is very important; sometimes a beginner developer is not familiar with your application. Of course, they don't know how you make the project. That's why we need to guide them with special instructions to help them run the project.&lt;/p&gt;

&lt;p&gt;If you have other links about how to get started, all you need to add are the links. So the user can view the better instruction&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%2Fm6sh00wujdaahvmivd5l.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%2Fm6sh00wujdaahvmivd5l.png" alt="Getting started" width="800" height="334"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Acknowledge
&lt;/h2&gt;

&lt;p&gt;Sometimes your project's readme needs to add detailed information about your project and allow the user to peek at what exactly you're doing. This section can be include some section parts like&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Feature - Tell what feature, problem solving in the project&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reference - If your project is get inspired by another project explain the chronology, or give a link to it&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tech stacks - Give the user top level information about what technology you're using the build the awesome projects&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Scrennshot: Add some visual references to your project. This can be your app design or overview&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Supports
&lt;/h2&gt;

&lt;p&gt;If your project becomes bigger or more popular, start by adding a support section. There are a wide range of ways people can help your project. There are several you can add to support including&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Contributors: List or add links to people who are building the project with you, helping you fix issues, or adding features.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Sponsors: Some people or companies that spend money to invest in your project You can add the links, images or mention it&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Contributing guides
&lt;/h2&gt;

&lt;p&gt;Guide some people who want to contribute to your project by adding this section. So people can understand your behavior and some rules when working. You can also mention some documents that cover this information.  &lt;/p&gt;

&lt;p&gt;Inside your contribution, you may also find some guides, like a code of conduct or changelog.&lt;/p&gt;

&lt;h2&gt;
  
  
  Roadmaps
&lt;/h2&gt;

&lt;p&gt;If your project is being developed or is in progress, start by adding the roadmap or mentioning some document to let other people know what you or your team will do next.&lt;/p&gt;

&lt;h2&gt;
  
  
  Credits
&lt;/h2&gt;

&lt;p&gt;If you create the project as a team, start mentioning your team in their account. Social media or email. You should care about your team's hard work; by mentioning them, you will help them become popular and gain a great reputation.&lt;/p&gt;

&lt;h2&gt;
  
  
  License
&lt;/h2&gt;

&lt;p&gt;Tell the people what they can and can't do with your project. This can be the last part of the README. There are some licenses that you can choose for your open-source project. Of course, it depends on your preferences.&lt;/p&gt;

&lt;p&gt;If you wonder how to pick and use a license, this website will help you pick the right license. Navigate to &lt;a href="https://choosealicense.com/" rel="noopener noreferrer"&gt;https://choosealicense.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, from the content above, you can add a better readme. I have some references or examples of the great readme that might help you out. You can see here&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/nestjs/nest" rel="noopener noreferrer"&gt;https://github.com/nestjs/nest&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/PostHog/posthog" rel="noopener noreferrer"&gt;https://github.com/PostHog/posthog&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you have any ideas or think something is missing in the post above, please comment below and let me know your amazing opinion.&lt;/p&gt;

</description>
      <category>git</category>
      <category>documentation</category>
      <category>github</category>
    </item>
    <item>
      <title>Create NestJS API using Typescript, MongoDB, Docker, Docker Compose</title>
      <dc:creator>Nyoman Sunima</dc:creator>
      <pubDate>Sun, 14 May 2023 07:33:02 +0000</pubDate>
      <link>https://forem.com/nyomansunima/create-nestjs-api-using-typescript-mongodb-docker-docker-compose-29k9</link>
      <guid>https://forem.com/nyomansunima/create-nestjs-api-using-typescript-mongodb-docker-docker-compose-29k9</guid>
      <description>&lt;p&gt;Ok, let's create a simple CRUD backend API for your app using the:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;NestJS&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;MongoDB&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Docker&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Docker Compose&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Mongoose&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Typescript&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What you're learn
&lt;/h2&gt;

&lt;p&gt;In this tutorial you will learn how to create a basic API using Nestjs as the core backend, MongoDB as your database, Mongoose as the database client to connect with NestJS, Docker &amp;amp; Docker Compose as your application runner in the container.&lt;/p&gt;

&lt;p&gt;We will make something basic just running the crud operation for user data including the name, email, and bio. You can customize and expand this tutorial based on your preference. At the end of the tutorial, I will share the project repository, so you can easily clone and try it on your machine computer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Architecture
&lt;/h2&gt;

&lt;p&gt;So, before creating the application let's see how the application work, and how the application can be structured.&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%2F5vzhg0h2xdvid3x7c4q6.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%2F5vzhg0h2xdvid3x7c4q6.png" alt="Backend API Architecture" width="800" height="569"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Create application
&lt;/h2&gt;

&lt;p&gt;First, we need to create our base application using NestJS. Start to create boilerplate code by running&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx @nestjs/cli new nestjs-backend-api
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will trigger the NestJS cli to create a Nest application starter. Nest also already install some dependencies for the application. Wait a second after the installation is finished.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install dependencies
&lt;/h2&gt;

&lt;p&gt;Let's install some dependencies to support the application. I will cover and explain what, and why you should install this dependency in your application.&lt;/p&gt;

&lt;p&gt;Now run this command in your application terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i &lt;span class="nt"&gt;-S&lt;/span&gt; @nestjs/config @nestjs/mongoose @nestjs/swagger @nestjs/throttler class-transformer class-validator compression helmet mongoose
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By running the command above you will be install several dependencies including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;@nestjs/config&lt;/strong&gt; - Allow to resolve the configuration including using the .env file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;@nestjs/mongoose&lt;/strong&gt; - The mongoose module in nestjs&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;@nestjs/swagger&lt;/strong&gt; - Allow NestJS to use OpenAPI Specification, and use the mapped type including partial, omit, etc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;@nestjs/throttler&lt;/strong&gt; - Rate limiter module for application&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;class-transformer&lt;/strong&gt;, &lt;strong&gt;class-validator&lt;/strong&gt; - Used to manage the application object transform and validation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;compression&lt;/strong&gt; - Allow to compress the body response through Gzip&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;helmet&lt;/strong&gt; - App protection to avoid the brute force XSS&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;mongoose&lt;/strong&gt; - Using to connect MongoDB to the application&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Update the project script
&lt;/h2&gt;

&lt;p&gt;Update the script to become more clear. We need to change the preview and start using a new command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"build"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"nest build"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"format"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"prettier --write &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;src/**/*.ts&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;test/**/*.ts&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"preview"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"nest start"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"dev"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"nest start --watch"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"debug"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"nest start --debug --watch"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"node dist/main"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"lint"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"eslint &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;{src,apps,libs,test}/**/*.ts&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt; --fix"&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;"jest"&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:watch"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"jest --watch"&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:cov"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"jest --coverage"&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:debug"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand"&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:e2e"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"jest --config ./test/jest-e2e.json"&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;/div&gt;



&lt;p&gt;After changing to this object, now you can easily run applications using&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;npm run dev&lt;/strong&gt; To run on a development server&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;npm run preview&lt;/strong&gt; Running the prebuild application to preview&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;npm run start&lt;/strong&gt; To run the application on production mode&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Bootstrap the application
&lt;/h2&gt;

&lt;p&gt;Now let's jump into the &lt;strong&gt;src/main.ts&lt;/strong&gt; file. Then change the code using this code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;NestFactory&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="s1"&gt;@nestjs/core&lt;/span&gt;&lt;span class="dl"&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;AppModule&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="s1"&gt;./app.module&lt;/span&gt;&lt;span class="dl"&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;ValidationPipe&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;VersioningType&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="s1"&gt;@nestjs/common&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;helmet&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;helmet&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;compression&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;compression&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;PORT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;parseInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PORT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;4000&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;bootstrap&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&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;NestFactory&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="nx"&gt;AppModule&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="c1"&gt;// register all plugins and extension&lt;/span&gt;
  &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enableCors&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="s1"&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;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;useGlobalPipes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ValidationPipe&lt;/span&gt;&lt;span class="p"&gt;({}))&lt;/span&gt;
  &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enableVersioning&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;VersioningType&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;URI&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;helmet&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
  &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;compression&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;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;`🚀 Application running at port &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;PORT&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;bootstrap&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;lets me explain. First, we need to import all dependencies, and settings into. Then start to use some middleware including the compression, and helmet. Then start o enable the cross-origin sharing resources. You also can change the Cors settings.&lt;/p&gt;

&lt;p&gt;Enable to global validation pipe, by using global validation, we automatically use the class-transform and class-validator class. When something error happens in the object, the error will be shown as a response.&lt;/p&gt;

&lt;p&gt;Enable the versioning by using URI Type. You can easily manage the version in the controller. This way helps you add some changes in your API without effect the below version.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap the app module
&lt;/h2&gt;

&lt;p&gt;To ensure all applications running you should import all feature modules and another module into the application module. Because if you see in the &lt;strong&gt;main.ts&lt;/strong&gt; file the best application is to create the app from AppModule.&lt;/p&gt;

&lt;p&gt;Change the app module using this code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&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="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@nestjs/common&lt;/span&gt;&lt;span class="dl"&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;AppController&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="s1"&gt;./app.controller&lt;/span&gt;&lt;span class="dl"&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;ConfigModule&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="s1"&gt;@nestjs/config&lt;/span&gt;&lt;span class="dl"&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;ThrottlerModule&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="s1"&gt;@nestjs/throttler&lt;/span&gt;&lt;span class="dl"&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;UserModule&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="s1"&gt;./user/user.module&lt;/span&gt;&lt;span class="dl"&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;MongooseModule&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="s1"&gt;@nestjs/mongoose&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Module&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;imports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nx"&gt;ConfigModule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forRoot&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;isGlobal&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="nx"&gt;ThrottlerModule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forRoot&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;ttl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt;
    &lt;span class="nx"&gt;MongooseModule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forRoot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DATABASE_URI&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;dbName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DATABASE_NAME&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DATABASE_USER&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DATABASE_PASS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;}),&lt;/span&gt;

    &lt;span class="c1"&gt;// feature module&lt;/span&gt;
    &lt;span class="nx"&gt;UserModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;controllers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;AppController&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AppModule&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First, we define the class with a module decorator and define the properties inside. Inside the import is used to import the application module. From, your local module or from dependencies.&lt;/p&gt;

&lt;p&gt;So first let's import the Config module, remember the isGlobal is set to true. This will allow you to use your configuration, environment, and settings inside all of your application scopes.&lt;/p&gt;

&lt;p&gt;Add the Throttler module and give the limit and ttl. This will protect our backend API from brute-force attacks. The user will only allow access to the same API resource up to 10 times, then wait a minute to try. If you wonder about this, you can learn more about brute force attack security.&lt;/p&gt;

&lt;p&gt;Install the Mongoose module to connect with MongoDB. Please specify the URI, and the authentication using username, and password. I will cover this using the .env file later. So stay tuned.&lt;/p&gt;

&lt;p&gt;Install the feature module, we will cover this later.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create User feature
&lt;/h2&gt;

&lt;p&gt;Moving into the user feature, we will need set up and create a new module called. User. inside the user feature, we will handle the user information including username, password, bio, email, and full name.&lt;/p&gt;

&lt;p&gt;In this module, we will handle the CRUD a.k.a (Create, Read, Update, Delete) operation for the user. So with that said let's jump into it.&lt;/p&gt;

&lt;p&gt;Inside the &lt;strong&gt;src&lt;/strong&gt; folder create a new folder called &lt;strong&gt;user&lt;/strong&gt;. All of your module files including schema, service, provider, and model inside this folder.&lt;/p&gt;

&lt;p&gt;so make a new file called &lt;code&gt;user.schema.ts&lt;/code&gt; . inside the model folder Then paste this code inside&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Prop&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Schema&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;SchemaFactory&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="s1"&gt;@nestjs/mongoose&lt;/span&gt;&lt;span class="dl"&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;HydratedDocument&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="s1"&gt;mongoose&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;UserDocument&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;HydratedDocument&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Schema&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;users&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;timestamps&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="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Prop&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="nx"&gt;fullName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;

  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Prop&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;

  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Prop&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="nx"&gt;bio&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;

  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Prop&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;UserSchema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;SchemaFactory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createForClass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this file that is used to manage the user collection on MongoDB. using timestamp allows us to automatically add the createdAt and updatedAt properties in Mongodb. After the model was defined. We need to create the user's schema using schema factory from Mongoose.&lt;/p&gt;

&lt;p&gt;Create a new file called user.input.ts inside the model folder. Then put this code inside.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;OmitType&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="s1"&gt;@nestjs/swagger&lt;/span&gt;&lt;span class="dl"&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;IsEmail&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;IsString&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="s1"&gt;class-validator&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CreateUserInput&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;IsString&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="nx"&gt;fullName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;

  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;IsEmail&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;

  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;IsEmail&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="nx"&gt;bio&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;

  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;IsString&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UpdateUserInput&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;OmitType&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;CreateUserInput&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;password&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kd"&gt;const&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;This model is specific to using input from the controller. So we set all input in one place. Don't forget to use the class validator to validate the input before the user is processed.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;UpdateUserInput&lt;/strong&gt; extends the omit type from &lt;strong&gt;CreateUserInput&lt;/strong&gt; class. This comes from &lt;strong&gt;@nestjs/swagger&lt;/strong&gt;. As I say you can use the same class and omit the type to remove the specific property. So you don't need to create it twice. You can explore more about Swagger later.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create UserPayload
&lt;/h3&gt;

&lt;p&gt;We need to create a type to specify what return to the client. That's why we called it payload. Create a new file called &lt;code&gt;user.payload.ts&lt;/code&gt; inside the &lt;strong&gt;model&lt;/strong&gt; folder, then put this code inside.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;PartialType&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="s1"&gt;@nestjs/swagger&lt;/span&gt;&lt;span class="dl"&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;User&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="s1"&gt;./user.schema&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserPayload&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;PartialType&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;createdA&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;
  &lt;span class="nx"&gt;updateAt&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As I say we use the &lt;strong&gt;@nestjs/swagger&lt;/strong&gt; package here. The PartialType allows us to use the same object to extend it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create User Service
&lt;/h3&gt;

&lt;p&gt;Create a new file called &lt;strong&gt;user.service.ts&lt;/strong&gt; then put this code inside the file. This will create a new logic to handle the user.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Injectable&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;NotFoundException&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="s1"&gt;@nestjs/common&lt;/span&gt;&lt;span class="dl"&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;InjectModel&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="s1"&gt;@nestjs/mongoose&lt;/span&gt;&lt;span class="dl"&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;User&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="s1"&gt;./model/user.schema&lt;/span&gt;&lt;span class="dl"&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;Model&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="s1"&gt;mongoose&lt;/span&gt;&lt;span class="dl"&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;CreateUserInput&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;UpdateUserInput&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="s1"&gt;./model/user.input&lt;/span&gt;&lt;span class="dl"&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;UserPayload&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="s1"&gt;./model/user.payload&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Injectable&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(@&lt;/span&gt;&lt;span class="nd"&gt;InjectModel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;userModel&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Model&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;createUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;CreateUserInput&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;UserPayload&lt;/span&gt;&lt;span class="o"&gt;&amp;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;createdUser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;userModel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&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;createdUser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;findUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;UserPayload&lt;/span&gt;&lt;span class="o"&gt;&amp;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;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findOne&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="nx"&gt;id&lt;/span&gt; &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nf"&gt;exec&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;NotFoundException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`User with email id:&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; not found `&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;user&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;listUser&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;UserPayload&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;updateUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;UpdateUserInput&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;UserPayload&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;updateOne&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="nx"&gt;id&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;updatedUser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;updatedUser&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;deleteUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;deleteOne&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="nx"&gt;id&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;This service handles the CRUD Operation for users, including creating a new user, listing all users, reading details, deleting, and updating. Inside the service constructor, we inject the &lt;strong&gt;UserModel&lt;/strong&gt; using &lt;strong&gt;UserSchema.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Create user controller
&lt;/h3&gt;

&lt;p&gt;All the API endpoints, paths, versions, and methods are placed here. Now create a new file called &lt;code&gt;user.controller.ts&lt;/code&gt; inside the top-level user folder. Then put this code inside.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Body&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Controller&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Delete&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Param&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Post&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Put&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="s1"&gt;@nestjs/common&lt;/span&gt;&lt;span class="dl"&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;CreateUserInput&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="s1"&gt;./model/user.input&lt;/span&gt;&lt;span class="dl"&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;UserService&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="s1"&gt;./user.service&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Controller&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;users&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserController&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nx"&gt;userService&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;UserService&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="nd"&gt;Post&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="nf"&gt;createUser&lt;/span&gt;&lt;span class="p"&gt;(@&lt;/span&gt;&lt;span class="nd"&gt;Body&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;CreateUserInput&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;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/list&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nf"&gt;listUser&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;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listUser&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="nd"&gt;Get&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="nf"&gt;findUser&lt;/span&gt;&lt;span class="p"&gt;(@&lt;/span&gt;&lt;span class="nd"&gt;Param&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="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&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;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Put&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="nf"&gt;updateUser&lt;/span&gt;&lt;span class="p"&gt;(@&lt;/span&gt;&lt;span class="nd"&gt;Param&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="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Body&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;CreateUserInput&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;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;updateUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;body&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="nd"&gt;Delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/:id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nf"&gt;deleteUser&lt;/span&gt;&lt;span class="p"&gt;(@&lt;/span&gt;&lt;span class="nd"&gt;Param&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="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&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;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;deleteUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create user module
&lt;/h3&gt;

&lt;p&gt;Now import all code and wrap it inside the user module. Create a new file called &lt;strong&gt;user.module.ts&lt;/strong&gt; Inside the user. Then put this code inside&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&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="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@nestjs/common&lt;/span&gt;&lt;span class="dl"&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;UserService&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="s1"&gt;./user.service&lt;/span&gt;&lt;span class="dl"&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;UserController&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="s1"&gt;./user.controller&lt;/span&gt;&lt;span class="dl"&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;MongooseModule&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="s1"&gt;@nestjs/mongoose&lt;/span&gt;&lt;span class="dl"&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;User&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;UserSchema&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="s1"&gt;./model/user.schema&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Module&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;imports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nx"&gt;MongooseModule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forFeature&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;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;UserSchema&lt;/span&gt; &lt;span class="p"&gt;}]),&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;providers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;UserService&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;controllers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;UserController&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserModule&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Don't forget to register the MongoDB schema Using &lt;code&gt;forFeature&lt;/code&gt;. then import the controller and service.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating environment
&lt;/h2&gt;

&lt;p&gt;Now let's create a new file called &lt;strong&gt;.env&lt;/strong&gt; Inside the root folder. Then put this code inside.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# APPS CONFIG&lt;/span&gt;
PORT &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="c"&gt;# YOUR_DATABASE_PORT&lt;/span&gt;

&lt;span class="c"&gt;# DATABASE CONFIGS&lt;/span&gt;
DATABASE_NAME &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="c"&gt;# YOUR_DATABASE_NAME&lt;/span&gt;
DATABASE_USER &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="c"&gt;# YOUR_DATABASE_USER&lt;/span&gt;
DATABASE_PASS &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="c"&gt;# YOUR DATABASE_PASS&lt;/span&gt;
DATABASE_URI &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="c"&gt;# YOUR_DATABASE_URI, example: mongodb://localhost:2701&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Change this environment using your own value.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dockerize the application
&lt;/h2&gt;

&lt;p&gt;We need to set up our database using docker. So we need to ensure the application running correctly.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create Dockerfile
&lt;/h3&gt;

&lt;p&gt;Let's create a new file called &lt;code&gt;Dockerfile&lt;/code&gt; in the root folder, then put this code inside.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Application Docker file Configuration&lt;/span&gt;
&lt;span class="c1"&gt;# Visit https://docs.docker.com/engine/reference/builder/&lt;/span&gt;
&lt;span class="c1"&gt;# Using multi stage build&lt;/span&gt;

&lt;span class="c1"&gt;# Prepare the image when build&lt;/span&gt;
&lt;span class="c1"&gt;# also use to minimize the docker image&lt;/span&gt;
&lt;span class="s"&gt;FROM node:14-alpine as builder&lt;/span&gt;

&lt;span class="s"&gt;WORKDIR /app&lt;/span&gt;
&lt;span class="s"&gt;COPY package*.json ./&lt;/span&gt;
&lt;span class="s"&gt;RUN npm install&lt;/span&gt;
&lt;span class="s"&gt;COPY . .&lt;/span&gt;
&lt;span class="s"&gt;RUN npm run build&lt;/span&gt;


&lt;span class="c1"&gt;# Build the image as production&lt;/span&gt;
&lt;span class="c1"&gt;# So we can minimize the size&lt;/span&gt;
&lt;span class="s"&gt;FROM node:14-alpine&lt;/span&gt;

&lt;span class="s"&gt;WORKDIR /app&lt;/span&gt;
&lt;span class="s"&gt;COPY package*.json ./&lt;/span&gt;
&lt;span class="s"&gt;ENV PORT=4000&lt;/span&gt;
&lt;span class="s"&gt;ENV NODE_ENV=Production&lt;/span&gt;
&lt;span class="s"&gt;RUN npm install&lt;/span&gt;
&lt;span class="s"&gt;COPY --from=builder /app/dist ./dist&lt;/span&gt;
&lt;span class="s"&gt;EXPOSE ${PORT}&lt;/span&gt;

&lt;span class="s"&gt;CMD ["npm", "run", "start"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This file will be used to configure our application to become a docker image. When running the docker-compose. Service will create a new image from our backend app. and then run it as a container.&lt;/p&gt;

&lt;p&gt;The concept is just to copy the &lt;strong&gt;package.json&lt;/strong&gt; and &lt;strong&gt;package-lock.json&lt;/strong&gt; file into the working directory, then install the deps. The command will build the application by running &lt;code&gt;npm run build&lt;/code&gt;, then copy all dist folders into a last image builder. At least we also add an &lt;strong&gt;env&lt;/strong&gt; file for PORT. So you can change the port dynamically without breaking the app.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create Docker Compose
&lt;/h3&gt;

&lt;p&gt;Docker Compose allow you to manage all service and container running inside your computer more easily. Compose allow you to define the service, image, and network in the same place without worrying about remembering command in your terminal. So that's why I recommended using docker-compose rather than using manual commands to run the container.&lt;/p&gt;

&lt;p&gt;Create a new file called &lt;code&gt;.docker-compose.yaml&lt;/code&gt; inside your root folder, then put this code inside.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Docker Compose Configuration&lt;/span&gt;
&lt;span class="c1"&gt;# visit https://docs.docker.com/compose/&lt;/span&gt;

&lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;3.8'&lt;/span&gt;
&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="c1"&gt;# app service for your backend&lt;/span&gt;
  &lt;span class="na"&gt;app&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;container_name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;backend&lt;/span&gt;
    &lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;context&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;./&lt;/span&gt;
      &lt;span class="na"&gt;dockerfile&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Dockerfile&lt;/span&gt;
    &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;DATABASE_NAME&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="c1"&gt;# DATABASE_NAME&lt;/span&gt;
      &lt;span class="na"&gt;DATABASE_USER&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="c1"&gt;# DATABASE_USER&lt;/span&gt;
      &lt;span class="na"&gt;DATABASE_PASS&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="c1"&gt;# DATABASE_PASS&lt;/span&gt;
      &lt;span class="na"&gt;DATABASE_URI&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="c1"&gt;# DATABASE_URI, example: mongodb://database:27017&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;4000:4000'&lt;/span&gt;
    &lt;span class="na"&gt;depends_on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;database&lt;/span&gt;

  &lt;span class="c1"&gt;# start the mongodb service as container&lt;/span&gt;
  &lt;span class="na"&gt;database&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;mongo:6.0&lt;/span&gt;
    &lt;span class="na"&gt;container_name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;mongodb&lt;/span&gt;
    &lt;span class="na"&gt;restart&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;always&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;27017:27017'&lt;/span&gt;
    &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;MONGO_INITDB_ROOT_USERNAME&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="c1"&gt;# DATABASE_NAME&lt;/span&gt;
      &lt;span class="na"&gt;MONGO_INITDB_ROOT_PASSWORD&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="c1"&gt;# DATABASE_USER&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This compose will create two services called app and database. Inside the app, you can see that without an image found. however, we found a context that reference to Dockerfile. This will allow the user to create a new image for the service.&lt;/p&gt;

&lt;p&gt;Otherside the &lt;strong&gt;mongo&lt;/strong&gt;, it's come from &lt;em&gt;dockerhub&lt;/em&gt; image with a 6.0 version. You also can define any variables and environment for the image including username, and password.&lt;/p&gt;

&lt;p&gt;NOTE: when connect database using docker network in application you will no longer access localhost, intead, you access using service name like database. Example if in local you can connect to database using &lt;strong&gt;mongodb://localhost:27017&lt;/strong&gt;, however after using docker you should use the service name like &lt;strong&gt;mongodb://database:27017&lt;/strong&gt; . This only work you don't expose the new network for database.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run backend api
&lt;/h2&gt;

&lt;p&gt;To run this application you can run by using this command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker-compose up &lt;span class="nt"&gt;-d&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will trigger docker compose to run 2 service at the sametime, also pulling the image and tun as docker container. To access you application, you can type &lt;strong&gt;&lt;a href="http://localhost:4000/v1/users" rel="noopener noreferrer"&gt;http://localhost:4000/v1/users&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Last words
&lt;/h2&gt;

&lt;p&gt;Before jumping please explore and try to code by yourlsef or understand the flow. All of this code are placed in my &lt;a href="https://github.com/tutorial-box/basic-essentials-nestjs-backenda-api" rel="noopener noreferrer"&gt;repository&lt;/a&gt; You can clone or fork this repo to understand how it's work.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Create PopUp Modal Using State Manager in React</title>
      <dc:creator>Nyoman Sunima</dc:creator>
      <pubDate>Thu, 22 Dec 2022 08:34:37 +0000</pubDate>
      <link>https://forem.com/nyomansunima/create-popup-modal-using-state-manager-in-react-5f62</link>
      <guid>https://forem.com/nyomansunima/create-popup-modal-using-state-manager-in-react-5f62</guid>
      <description>&lt;p&gt;Hey dude welcome, Today i want to continue a new article about the modal in react. This article is the next part of article before. if you're not know. Please read the article before about &lt;a href="https://dev.to/nyomansunima/how-to-create-modal-popup-in-react-3mk"&gt;Create Popup Modal In React&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this article we will learn about make a powerful and complex modal type in react using any State Manager&lt;/p&gt;

&lt;h2&gt;
  
  
  Background &amp;amp; Use Case
&lt;/h2&gt;

&lt;p&gt;Many of you may ask the same question about Why should use a State Manager to handle Modal?. Alright, To make any modal you can follow any approach like Using React Context or using Simple Method. However in Complex and Big Application we will handle many modal in single module. Also any modal will need in the global scope. &lt;/p&gt;

&lt;p&gt;That's why we can use the state manager to make the modal accessible from everywhere in your application components.&lt;/p&gt;

&lt;h2&gt;
  
  
  Concept
&lt;/h2&gt;

&lt;p&gt;To make a modal work with state manager it's kind a like easy stuff. We just need to make a simple modal, but to show and hide we can use the state manager. &lt;/p&gt;

&lt;p&gt;In this case i will pick simple and powerful state manager as example, Of course it's &lt;a href="https://github.com/pmndrs/zustand" rel="noopener noreferrer"&gt;zustand&lt;/a&gt;. you also can use ant state manager like &lt;code&gt;Recoil&lt;/code&gt;, &lt;code&gt;Jotail&lt;/code&gt;, &lt;code&gt;Redux&lt;/code&gt;, etc. The concep is pretty the same and you just need to modify a little bit. If you just want to make this as you're first time to using state manager i will recomended using zustand. &lt;/p&gt;

&lt;p&gt;Ok, before we jump in, to make this modal there some point as step by step.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create Simple Modal&lt;/li&gt;
&lt;li&gt;Create Hooks&lt;/li&gt;
&lt;li&gt;Handle Show &amp;amp; Hide&lt;/li&gt;
&lt;li&gt;Passing Data &amp;amp; Dynamic Content&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  1. Create Simple Modal
&lt;/h2&gt;

&lt;p&gt;We need to prepare and make any simple modal for the example. Create a new file call &lt;code&gt;StateModal.js&lt;/code&gt; and create a simple component with reference in modal &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%2Fwfx692xd1ruld9d96ptb.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%2Fwfx692xd1ruld9d96ptb.png" alt="Create Simple Modal" width="800" height="617"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you're not understand this part, please read my article before about &lt;a href="https://dev.to/nyomansunima/how-to-create-modal-popup-in-react-3mk"&gt;make simple modal in react&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Create Hooks
&lt;/h2&gt;

&lt;p&gt;The way we cna handle the modal in global, or component is by using the hooks. So the main key here's is the hooks. In this example i will using zustand. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First, Install the zustand in your react application
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  // install zustand using npm
  npm i -S zustand

  //install zustand using yarn
  yard add zustand
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Create a file in hooks folder call &lt;code&gt;modal.js&lt;/code&gt; and put the code to make a simple hooks for confirm modal&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%2Fs84yw4f4tjksdmowv8ke.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%2Fs84yw4f4tjksdmowv8ke.png" alt="Create hooks using zustand" width="800" height="526"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you need more than confirm modal, we can create a new modal and add new property in modal hooks to show and hide like before. &lt;/p&gt;

&lt;p&gt;And now, your hook are ready to use in any component to show the modal globaly. &lt;/p&gt;

&lt;h2&gt;
  
  
  3. Handle Show &amp;amp; Hide
&lt;/h2&gt;

&lt;p&gt;To handle the show the modal, first we need to put the hooks that specify to the modal component and one side in other component to show the modal like &lt;code&gt;Header&lt;/code&gt;, &lt;code&gt;Button&lt;/code&gt;, etc.&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%2F5h96b0silby61y9yhceh.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%2F5h96b0silby61y9yhceh.png" alt="Put Hooks in Modal Component" width="800" height="344"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To show the modal we need to put the hooks in parent where will trigger the modal to show. Example in App will show the modal form button &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%2Fdo4hq5aa9srtwjen2fml.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%2Fdo4hq5aa9srtwjen2fml.png" alt="Trigger Modal From Button" width="800" height="508"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, we need to modify the modal and only show if the state from hook has changed. Inside the modal component we just need to wrap the modal in if statement&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%2Fd1i1aclffy36g3odcbxh.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%2Fd1i1aclffy36g3odcbxh.png" alt="Wrap in if Statement" width="800" height="453"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you're ready to show the modal. To hide the modal you can follow the close Manualy using hooks by calling &lt;code&gt;modal.confirm.hide()&lt;/code&gt; or using any approach for closing modal like when user click outside, or by pressing &lt;code&gt;Esc&lt;/code&gt; key&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Passing Data &amp;amp; Dynamic Content
&lt;/h2&gt;

&lt;p&gt;The way we can passing some data like title, desc, or any data into the modal from hooks is by passing some argument from the &lt;code&gt;show&lt;/code&gt; method. But before that we need to change the hooks a little bit. &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%2F9ioyqcxj4s6ilk2m62v6.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%2F9ioyqcxj4s6ilk2m62v6.png" alt="Passing Data &amp;amp; Dynamic Content" width="800" height="417"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ok, that the point to make the simple modal using State Manager. If you have any preference for State Manager you also can follow the same way to make this work. &lt;/p&gt;

&lt;p&gt;If you have any trouble, or struggle please contact me. Please give any comment and like. &lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to Create Popup Modal In React</title>
      <dc:creator>Nyoman Sunima</dc:creator>
      <pubDate>Wed, 21 Dec 2022 05:48:49 +0000</pubDate>
      <link>https://forem.com/nyomansunima/how-to-create-modal-popup-in-react-3mk</link>
      <guid>https://forem.com/nyomansunima/how-to-create-modal-popup-in-react-3mk</guid>
      <description>&lt;p&gt;After some explorations and make any projects. I found that create the modal kind a like an easy task when building web application with react, But most of the beginner will confused at the first time. &lt;/p&gt;

&lt;p&gt;This article is purposed to beginner of developer that work with react project. If you're already know about this concept You can skip this content, or just give me any of approach in the comment below.&lt;/p&gt;

&lt;p&gt;Opps, to see the result of this project, you can see the preview at &lt;a href="https://modal-in-react.vercel.app/" rel="noopener noreferrer"&gt;https://modal-in-react.vercel.app/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example you will find the 3 way to make any modal or popup, alert in your react application. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create Simple Modal&lt;/li&gt;
&lt;li&gt;Create Modal Using State Manager&lt;/li&gt;
&lt;li&gt;Create Modal Using React Context&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The different approach may work for you and your project. This method can you pick based on your project scope and possibility.&lt;/p&gt;

&lt;p&gt;But in this article i will share about simple and traditional modal. Please waiting, i will make the article in the next day. &lt;/p&gt;

&lt;h2&gt;
  
  
  Concept
&lt;/h2&gt;

&lt;p&gt;Before we just let me explain about the concept behind the modal and how it's work. Today i will explain to you what should be inside the modal to make it become more attractive and reactive with this several points.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Define Modal layout&lt;/li&gt;
&lt;li&gt;Styling Modal &lt;/li&gt;
&lt;li&gt;Show &amp;amp; Hide Modal&lt;/li&gt;
&lt;li&gt;Close Modal When Outside Clicked&lt;/li&gt;
&lt;li&gt;Close Modal When &lt;code&gt;Esc&lt;/code&gt; Pressed&lt;/li&gt;
&lt;li&gt;Adding Confirm &amp;amp; Cancel Button&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  1. Define Modal Layout
&lt;/h2&gt;

&lt;p&gt;Ok, when we create a modal we need to structure the modal base on the purpose and the design. But in general modal contain the &lt;code&gt;header&lt;/code&gt;, &lt;code&gt;body&lt;/code&gt;, and &lt;code&gt;footer&lt;/code&gt; section. You can see the detail in the image below.&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%2Fnc4rextmgbhmpfhrbpfl.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%2Fnc4rextmgbhmpfhrbpfl.png" alt="Modal Layout" width="800" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see above the modal layout, in each of section will use for different function. Header mainly to show the title of modal, You can put the content in the body of your modal. Then the footer use to show the confirm, cancel, and any action button that user can pick and click.&lt;/p&gt;

&lt;p&gt;To start let's create a new modal component call &lt;code&gt;SimpleModal.js&lt;/code&gt;, then inside you need to create a react component.&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%2F4ywtk12i4m6gqqjee9w6.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%2F4ywtk12i4m6gqqjee9w6.png" alt="Modal Layout" width="800" height="455"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We should pass some of props like &lt;code&gt;show&lt;/code&gt;, &lt;code&gt;onClose&lt;/code&gt;, &lt;code&gt;onConfirm&lt;/code&gt;, and &lt;code&gt;onCancel&lt;/code&gt;. I will explain all of the passed props later. &lt;/p&gt;

&lt;p&gt;We also create some class style for the modal. &lt;code&gt;.modal-backdrop&lt;/code&gt; will cover all of the modal and showing as fixed element, including showing the backdrop background. Then following with the &lt;code&gt;.modal-content&lt;/code&gt; that include the element like &lt;code&gt;modal-header&lt;/code&gt;, &lt;code&gt;modal-body&lt;/code&gt;, and &lt;code&gt;modal-footer&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Styling Modal
&lt;/h2&gt;

&lt;p&gt;to styling the modal we can easily add the css to the components. Create a file call &lt;code&gt;main.css&lt;/code&gt; then import it into the components&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%2Fx7eod2o8jxl60skqfmll.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%2Fx7eod2o8jxl60skqfmll.png" alt="Modal Backdrop Style" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fier1pdhq5stgpkmmmidu.jpeg" 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%2Fier1pdhq5stgpkmmmidu.jpeg" alt="Modal Content Style" width="800" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcd9tg7senwlg86ymd5sc.jpeg" 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%2Fcd9tg7senwlg86ymd5sc.jpeg" alt="Modal Header Style" width="800" height="254"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwsr1tdp47xczue9c1jlb.jpeg" 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%2Fwsr1tdp47xczue9c1jlb.jpeg" alt="Modal Body" width="800" height="235"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fncdlx563rgnbyrrq0gcx.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%2Fncdlx563rgnbyrrq0gcx.png" alt="Modal Footer Style" width="800" height="309"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You, also can add some element and change the style based on your preference.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Show &amp;amp; Hide Modal
&lt;/h2&gt;

&lt;p&gt;The most important thing in modal in react is the way to show and hide. In this post we're just cover to manage show and hide using simple state method. &lt;/p&gt;

&lt;p&gt;Add a state to your parent component , where the modal will be placed. This state will be used to manage the show and hide of the modal. &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%2Ffy8wbyb0j9tl0dexnv8j.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%2Ffy8wbyb0j9tl0dexnv8j.png" alt="State of Modal" width="800" height="290"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;create the hide and show method that will manipulate the state. &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%2F9h58gokuzbk550ydsjmn.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%2F9h58gokuzbk550ydsjmn.png" alt="Show hide method" width="800" height="473"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After all, we should pass the function and state into the component props to the children.&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%2Fgc7puxu2u10l4fo6sbx7.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%2Fgc7puxu2u10l4fo6sbx7.png" alt="Pass props" width="800" height="361"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now to make this work, you should create a button to trigger to show the modal. Now to make this work we should modify the content of modal and ensure to show the modal only if the show props is equals to &lt;code&gt;true&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc2j8qkgoivx167iay1ju.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%2Fc2j8qkgoivx167iay1ju.png" alt="Only Show if show true" width="800" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Close Modal When Outside Clicked
&lt;/h2&gt;

&lt;p&gt;Some modal also will be closed if the user click outside of the modal element, or user click on other components. This is very interesting feature and you should implement in every popup on react. &lt;/p&gt;

&lt;p&gt;To make this work is very simple by identify the element that clicked by the user. And if the element is not the modal, the modal will be closed. &lt;/p&gt;

&lt;p&gt;OK, first we should do is to add the listener via the &lt;code&gt;useEffect&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp00nzyr58opghkrpq3by.jpeg" 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%2Fp00nzyr58opghkrpq3by.jpeg" alt="Implement Listener when clicked" width="800" height="527"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we will handle the function of listener when the user clicked the mouse. We need to create the ref for modal first, then pass the ref of modal into the modal content. Then inside the method, we will ensure all deps, and props was define. The next step is to check if the element of clicked is contain the modal element. if now we will call the close function that we pass from the props. &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%2F3n6l6rbkb6znvid03w79.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%2F3n6l6rbkb6znvid03w79.png" alt="Close modal when clicked outside" width="800" height="507"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, if the user click outside of the content element, or in backdrop. The modal will be automatically closed.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Close Modal When &lt;code&gt;Esc&lt;/code&gt; Pressed
&lt;/h2&gt;

&lt;p&gt;To implement this feature, basically same like implement the outside click. The difference is we need to listen to the &lt;code&gt;keydown&lt;/code&gt; event and also close if the key pressed is &lt;code&gt;Escape&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjzqssbw31eoeje6rhquv.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%2Fjzqssbw31eoeje6rhquv.png" alt="Close Modal When  raw `Esc` endraw  key pressed" width="800" height="537"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Adding Confirm &amp;amp; Cancel Button
&lt;/h2&gt;

&lt;p&gt;The modal also need to contain at least confirm button. This will trigger the modal to close and do another action like saving data, delete and more. &lt;/p&gt;

&lt;p&gt;We need to create couple button element inside the modal footer. then add the clicked function to handle the button trigger. &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%2Funs8jrqexbv5m7gwdyww.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%2Funs8jrqexbv5m7gwdyww.png" alt="Adding Confirm &amp;amp; Cancel Button" width="800" height="730"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To use the confirm and cancel button and adding some callback when it's clicked we need to pass methods from the component props.&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%2F501oxi96omv9m7wel5dg.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%2F501oxi96omv9m7wel5dg.png" alt="Adding confirm &amp;amp; Close Callback" width="746" height="513"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Good job bro. Now you're have a super rich modal with many feature. &lt;/p&gt;

&lt;h2&gt;
  
  
  What's Next ?
&lt;/h2&gt;

&lt;p&gt;This article is just teach you about make an simple modal with simple design. However in many case you also need to make very complicated design of modal. Also may need to use state manager, hooks for advance use case. &lt;/p&gt;

&lt;p&gt;I will share to you about advance modal using state manager, or context in react for more easy to manage in big scale project. &lt;/p&gt;

&lt;p&gt;You can explore this tutorial by adding any modification including dynamic content by passed the props or other.&lt;/p&gt;

&lt;p&gt;If you're have any suggestion or any argument about this article please comment below. If this article help you please like this article and follow me. &lt;/p&gt;

&lt;p&gt;Opps, i almost forget. You can see the detail of this project in the Github Repository &lt;a href="https://github.com/nyomansunima/modal-in-react" rel="noopener noreferrer"&gt;https://github.com/nyomansunima/modal-in-react&lt;/a&gt;. Also follow my twitter &lt;a href="https://twitter.com/nyomansunima" rel="noopener noreferrer"&gt;@nyomansunima&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope you're understand and Start endeavor.&lt;/p&gt;

</description>
      <category>react</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>5 Tips to improve your next UI Design project</title>
      <dc:creator>Nyoman Sunima</dc:creator>
      <pubDate>Tue, 14 Dec 2021 15:16:28 +0000</pubDate>
      <link>https://forem.com/nyomansunima/5-tips-to-improve-your-next-ui-design-project-1j27</link>
      <guid>https://forem.com/nyomansunima/5-tips-to-improve-your-next-ui-design-project-1j27</guid>
      <description>&lt;p&gt;Hey everyone, welcome to the first of my article I'm happy to see you're here.&lt;/p&gt;

&lt;p&gt;Today I wanna share with you about some tips for designers especially for UI to improve the result of your design.&lt;/p&gt;

&lt;p&gt;What's, What that mean. Yeah boy, I wanna share some tips to make your design look better, friendly, and cool 😍😍. This takes from my mistake when I jump into the design but don't worry the whole process will also increase your skill step by step.&lt;/p&gt;

&lt;p&gt;Ok, without waiting any longer, Let's jump right into it.&lt;/p&gt;

&lt;h2&gt;
  
  
  1.  Use Less Typography
&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%2F0unglluqv12jxb8pg6hq.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%2F0unglluqv12jxb8pg6hq.jpg" alt="Less Typhography" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ok, what's going on here. when I first time jumps into a design I feel so blank, with no idea, no topic in my mind. So I just let myself to design whatever I want to do and then pick many fonts maybe 3-5 fonts in my design project.&lt;/p&gt;

&lt;p&gt;Avoid this mistake, Only use one typography in your design, and if the design is more complex you can add one font to your design.&lt;/p&gt;

&lt;p&gt;This will help your design be more neat, clean, and less boilerplate, So think about this.&lt;/p&gt;

&lt;p&gt;if you wanna the best free fonts for design, wait for the next post.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Limited Colors Palletes
&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%2F0tb5ccmf9ffxs2ebtogp.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%2F0tb5ccmf9ffxs2ebtogp.jpg" alt="Limited Colors Palletes" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are so many designers who add a lot of color to design but don't forget colors bring identity. only focusing on primary color don't let the main color disappear from your design.&lt;/p&gt;

&lt;p&gt;In my case, I just use the main color for accent and primary. 1 color for background, 2 colors for text, and some supported colors like success, danger, warning.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Give More Space
&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%2Fodjbmgom22vvmuivyaom.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%2Fodjbmgom22vvmuivyaom.jpg" alt="Give More Space" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Letting your design too close is a mistake. If you wanna get a better design use more space in your design component, assets, and text.&lt;/p&gt;

&lt;p&gt;Why?, I don't think so !. Ok, let me explain. &lt;br&gt;
with enough space, your eye will enable to process the main object you wanna appear and will easily see the main focus in your design. This means, the design will be user-friendly and you got the purpose.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Keep concistency
&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%2Fioov7dvurjk6gfj7qrzd.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%2Fioov7dvurjk6gfj7qrzd.jpg" alt="Keep concistency" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Consistency ?, What? &lt;br&gt;
Yes, I don't wanna debate with this one, but you should do this. no matter how good you create a design, picking color, take typography, and UX research. Please make sure your design is consistent.&lt;/p&gt;

&lt;p&gt;Example: When you create a post card on the home screen and add around padding 16px and the color white, after that you create one again, again, and again the same card but without the same padding (you may pick 20px). This will make your design inconsistent, the impact will make your design like trash.&lt;/p&gt;

&lt;p&gt;So the best way to do this is to create a component, style, and colors component. if you are interested in this topic, the next article will discuss more components, and style.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Less is More
&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%2Fbhnblalln1sff8dj1zye.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%2Fbhnblalln1sff8dj1zye.jpg" alt="Less is More" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Keep your object under control, don't let your design full with unnecesary object like too much text, icon, button, and other boilerplates.&lt;/p&gt;

&lt;p&gt;In my experience, to make a clean, neat and friendly design need a less object into your design. I dont wanna to teaching you, but trust me use just needed info text, color, and object into your design will help it better.&lt;/p&gt;

&lt;p&gt;Ok, just that the tips today i wanna share with you all dude. If you had and idea, or suggest for the next article please give your comment. &lt;/p&gt;

&lt;p&gt;Sonibble will release twice article a week, so stay tune to get update. In the end i wanna say "Don't let your self become noob 😙😙"&lt;/p&gt;

</description>
      <category>ux</category>
      <category>uiweekly</category>
      <category>design</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
