<?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: Srujal Patel</title>
    <description>The latest articles on DEV Community by Srujal Patel (@iamsrujal).</description>
    <link>https://dev.to/iamsrujal</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%2F297108%2F9fdccc07-34f5-430a-8198-cb8043eeea50.jpeg</url>
      <title>DEV Community: Srujal Patel</title>
      <link>https://dev.to/iamsrujal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/iamsrujal"/>
    <language>en</language>
    <item>
      <title>Nodejs Express Project Structure For REST API</title>
      <dc:creator>Srujal Patel</dc:creator>
      <pubDate>Tue, 04 Aug 2020 14:46:10 +0000</pubDate>
      <link>https://dev.to/iamsrujal/nodejs-express-project-structure-for-rest-api-37oa</link>
      <guid>https://dev.to/iamsrujal/nodejs-express-project-structure-for-rest-api-37oa</guid>
      <description>&lt;p&gt;Hello all,&lt;/p&gt;

&lt;p&gt;Before I start about the NodeJs project structure let me introduce myself. I am Srujal Patel, the Full Stack Web Developer.&lt;/p&gt;

&lt;p&gt;Do find for Nodejs project structure and you will find very few structures.&lt;br&gt;
In fact, most of the Nodejs tutorials also won't be using any proper file structure.&lt;/p&gt;

&lt;p&gt;Today I will explain to you my own Nodejs project structure created using express REST API.&lt;/p&gt;

&lt;p&gt;Let's start it will take 5 to 10 min read the whole blog and implementation will give you a real idea about this project structure.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1jivvqwedxyj68c92fin.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1jivvqwedxyj68c92fin.png" alt="File Structure Screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first config folder contains all the configuration variables JSON files.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8cmb7d7slkfnltzxa7x5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8cmb7d7slkfnltzxa7x5.png" alt="Config Folder Demo Screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Constant folder contains the const variable which can be used in the whole project. I have used two demo versions - one for sending the static message in response and the parent route name. &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F51b3bb5ud7r4ok62t9x6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F51b3bb5ud7r4ok62t9x6.png" alt="Constat Folder Sample"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Cors folder work as middleware in the whole project. I have created some sample middleware in the project like sending emails, check token for each and every route, and send the response after REST API execution has been finished.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fmpoo17exgt414v73y6ur.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fmpoo17exgt414v73y6ur.png" alt="Cors Folder Sample"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The routes folder is having 2 files one for creating the routes and another file is known as the controller.&lt;br&gt;
The controller file uses for controlling the flow like calling the service, taking the request and sending the response as well.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fuk6t1s23m1qrchyrraqn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fuk6t1s23m1qrchyrraqn.png" alt="Routes Folder Sample"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Service folder is having files for creating services.&lt;br&gt;
This file can be divided into two parts one for database related query and second for after getting the data from the database do some coding for business logic. But here I have considered both tasks will be kept in one place. (it's up to you if you want to divide, go for it).&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1aqufzip1kefnmqmt0mp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1aqufzip1kefnmqmt0mp.png" alt="Service Folder Sample"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The upload folder is having all the static file which can be used to retrieve without any API calling or basically without any authentication.&lt;/p&gt;

&lt;p&gt;Then the validation folder is having all the routes validation.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwtz1t8nov03vilgycc6r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwtz1t8nov03vilgycc6r.png" alt="Validation File Sample"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is a server file which is I think the heart of the node-express application. Server file will have the DB connection, starting the node-express application and many more.&lt;/p&gt;

&lt;p&gt;I Hope this file structure will help you to build projects.&lt;/p&gt;

&lt;p&gt;If you like this structure please don't forget to give me a star on Github.&lt;br&gt;
If you have any issue, suggestion, idea or modification please use GitHub to create an issue or pull request.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/iamsrujal" rel="noopener noreferrer"&gt;
        iamsrujal
      &lt;/a&gt; / &lt;a href="https://github.com/iamsrujal/nodejs-file-stucture-express" rel="noopener noreferrer"&gt;
        nodejs-file-stucture-express
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Nodejs Express Project File Structure For REST API
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Nodejs File Stucture Express&lt;/h1&gt;

&lt;/div&gt;
&lt;p&gt;Nodejs Project Structure For Express REST API&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;General Info&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;Sample Nodejs Project file structure architecture created by Srujal Patel&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Testing Locally&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;Make sure you have installed Nodejs, npm and git.
&lt;br&gt;
Note: npm is installed with Node.js&lt;/p&gt;
&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;git clone https://github.com/iamsrujal/nodejs-file-stucture-express.git

&lt;span class="pl-c1"&gt;cd&lt;/span&gt; nodejs-file-stucture-express

npm install or npm i

npm run dev (For Development environment) 

OR

npm run staging (For Staging environment)

OR

npm run prod (For Production environment)&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Contributing&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;License&lt;/h2&gt;

&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;You can check out the full license &lt;a href="https://github.com/iamsrujal/nodejs-file-stucture-express/blob/master/LICENSE" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;a href="https://choosealicense.com/licenses/mit/" rel="nofollow noopener noreferrer"&gt;MIT&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;



&lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/iamsrujal/nodejs-file-stucture-express" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


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