<?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: Kenas Zogara</title>
    <description>The latest articles on DEV Community by Kenas Zogara (@kenaszogara).</description>
    <link>https://dev.to/kenaszogara</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%2F288364%2F6594d977-f2e1-4031-a37d-70b9b4e3ae6c.jpeg</url>
      <title>DEV Community: Kenas Zogara</title>
      <link>https://dev.to/kenaszogara</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kenaszogara"/>
    <language>en</language>
    <item>
      <title>An MVC Generator for Your Next Express JS Project</title>
      <dc:creator>Kenas Zogara</dc:creator>
      <pubDate>Sun, 22 Aug 2021 11:35:43 +0000</pubDate>
      <link>https://dev.to/kenaszogara/an-mvc-generator-for-your-next-express-js-project-12he</link>
      <guid>https://dev.to/kenaszogara/an-mvc-generator-for-your-next-express-js-project-12he</guid>
      <description>&lt;p&gt;I'm tired of writing boilerplate codes for an MVC design pattern in my Express project. So I decided to create a generator for it. 🚀🚀&lt;/p&gt;

&lt;p&gt;The package for this tool, I named it VYNL, it is published in &lt;a href="https://www.npmjs.com/package/vynl" rel="noopener noreferrer"&gt;npm&lt;/a&gt; and you can start using it in your project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm install vynl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create an empty express project, then type in&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;What it does for you, is simple, it makes out your project directory like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.
|--auth
|    └──auth.js
|--config
|    └──config.json
|--docs
|    |--paths
|    |    |--index.js
|    |    └──users.js
|    └──schemas
|         |--index.js
|         └──users.js
|--migrations
|--models
|--routes
|--app.js
└──swagger.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It also creates these things out of the box for you:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A Users MVC (with Sequelize Model)&lt;/li&gt;
&lt;li&gt;Basic authentication using jsonwebtoken&lt;/li&gt;
&lt;li&gt;Swagger Documentation for the API routes.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Next, Adjust your project database configuration in &lt;code&gt;config/config.json&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Since the generator will only write codes for you, You are still required to install the packages needed to run the project yourself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm install sequelize jsonwebtoken swagger-ui-express mysql2 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;if you are using other database than mysql, check &lt;a href="https://sequelize.org/master/manual/getting-started.html" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then to generate a new MVC simply use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npx vynl generate:api -m &amp;lt;model_name&amp;gt; -f &amp;lt;model_fields&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;model_fields syntax: : and comma separated for the next field. Ex. &lt;code&gt;name:string,birth_date:string,email:string,password:string&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It also allows you to only generate a part of the MVC (ex. only the Model).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Generate Model
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npx vynl generate:model -m &amp;lt;model_name&amp;gt; -f &amp;lt;model_fields&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Generate Controller
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npx vynl generate:controller -m &amp;lt;model_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Generate Route
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npx vynl generate:route -r &amp;lt;route_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Generate Swagger Doc
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npx vynl generate:swagger -m &amp;lt;model_name&amp;gt; -f &amp;lt;model_fields&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's it. I hope this tool can help you in your next Express project.&lt;/p&gt;

&lt;p&gt;Cheers 🍷&lt;/p&gt;

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