<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rcoder0907</title>
    <description>The latest articles on DEV Community by Rcoder0907 (@rcoder0907).</description>
    <link>https://dev.to/rcoder0907</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%2F1076179%2F8e5e69aa-1097-400c-9cbb-ba387aec61d0.png</url>
      <title>DEV Community: Rcoder0907</title>
      <link>https://dev.to/rcoder0907</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rcoder0907"/>
    <language>en</language>
    <item>
      <title>Boilerplate code in Node Js</title>
      <dc:creator>Rcoder0907</dc:creator>
      <pubDate>Wed, 03 May 2023 16:17:31 +0000</pubDate>
      <link>https://dev.to/rcoder0907/boilerplate-code-in-node-js-kjo</link>
      <guid>https://dev.to/rcoder0907/boilerplate-code-in-node-js-kjo</guid>
      <description>&lt;p&gt;As I began developing REST APIs on the server side with Node.js, I repeatedly faced the challenge of determining the appropriate folder structure. Although there is no definitive answer to this issue, I discovered a Node.js folder structure and architecture that suited my requirements after reading several articles on the topic. In this post, I would like to share my approach to organizing and structuring Node.js REST APIs. Additionally, I have created a GitHub repository that includes a sample application which you can utilize as a template for your own project.&lt;/p&gt;

&lt;p&gt;It is worth noting that my implementation employs Express.js as the web framework and TypeORM as the ORM. However, adapting this folder structure to other frameworks should not be too difficult.&lt;/p&gt;

&lt;p&gt;The architecture mainly relies on a component-based approach, making it easier to request only the necessary data. For instance, we have a User component that encompasses all user-related information.&lt;/p&gt;

&lt;p&gt;Let’s start with the root directory.&lt;br&gt;
&lt;strong&gt;Directory: root&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LbYeDo2R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t5fcj7tzo5r59b6vr4nh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LbYeDo2R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t5fcj7tzo5r59b6vr4nh.png" alt="Image description" width="800" height="575"&gt;&lt;/a&gt;&lt;br&gt;
The root directory is fairly ordinary and ought to be familiar to you. It essentially constitutes a fundamental Node.js configuration that encompasses certain configuration files for linting, Docker, and other similar components.&lt;/p&gt;

&lt;p&gt;However, the most intriguing aspect of this structure lies within the contents of the "src" folder, which this post specifically discusses. Consequently, what precisely does this directory contain?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RHVxTsr6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b9gvyb5m2zzr9jxr9hbg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RHVxTsr6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b9gvyb5m2zzr9jxr9hbg.png" alt="Image description" width="800" height="379"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Directory: src/api&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9vD1I1mZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r3f5inyn7fqowuxilsnv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9vD1I1mZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r3f5inyn7fqowuxilsnv.png" alt="Image description" width="800" height="247"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Directory: src/api/components&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oJ9Di_Dj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aur78a7r22ohfhj3d33i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oJ9Di_Dj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aur78a7r22ohfhj3d33i.png" alt="Image description" width="800" height="355"&gt;&lt;/a&gt;&lt;br&gt;
At the core of our Node API based on components, we find the following: every component has its own set of routes, controllers, models, repositories, policies, tests, and templates.&lt;/p&gt;

&lt;p&gt;Now, let us delve into the User component and explore it in further detail.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Directory: src/api/components/user&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---sBwO4To--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t7j8fgj9b5vc9iq0utut.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---sBwO4To--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t7j8fgj9b5vc9iq0utut.png" alt="Image description" width="800" height="565"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Directory: src/services&lt;/strong&gt;&lt;br&gt;
This directory contains global services we might need for authorization, sending mails, caching, or helper methods for example.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---f075Cri--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c6yeaass54ay05haq2pl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---f075Cri--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c6yeaass54ay05haq2pl.png" alt="Image description" width="800" height="381"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Chekcout my github repo to see all the files and how code is organised&lt;br&gt;
&lt;a href="https://github.com/Rcoder0907/node-folder-structure"&gt;https://github.com/Rcoder0907/node-folder-structure&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
    </item>
  </channel>
</rss>
