<?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: Rhodlib</title>
    <description>The latest articles on DEV Community by Rhodlib (@rhodlib).</description>
    <link>https://dev.to/rhodlib</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%2F248926%2Ff9b41662-647f-4220-a7e4-e6e88829ef7f.png</url>
      <title>DEV Community: Rhodlib</title>
      <link>https://dev.to/rhodlib</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rhodlib"/>
    <language>en</language>
    <item>
      <title>My first blog with MERN Stack (Front-end)</title>
      <dc:creator>Rhodlib</dc:creator>
      <pubDate>Tue, 05 May 2020 20:09:10 +0000</pubDate>
      <link>https://dev.to/rhodlib/my-first-blog-with-mern-stack-front-end-16mg</link>
      <guid>https://dev.to/rhodlib/my-first-blog-with-mern-stack-front-end-16mg</guid>
      <description>&lt;h1&gt;
  
  
  All about my blog: Front-end
&lt;/h1&gt;

&lt;h1&gt;
  
  
  Front-end Blog: How?
&lt;/h1&gt;

&lt;p&gt;In this article, I'll explain how i create the front end of my blog, technologies and examples, but this isn't a guide step-by-step. It's simple because this project just centered in the back-end.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/rhodlib/mern_personal_blog/tree/master/client"&gt;here&lt;/a&gt; is all the code of the front-end&lt;/p&gt;

&lt;h2&gt;
  
  
  First read this
&lt;/h2&gt;

&lt;p&gt;This front-end it's very simple, you can use Redux/Context for state managment, the back end is ready for load many users but i only have one, mine. i use this for posting articles, this blog don't have box comment because is for documenting and save quick information for me, like notes. also you can user prop-types for props(it's a very good practice and really necesary for developing). this blog don't have front-end validations for login, because this project is for practicing backend. for this reazons the front is very simple. Be creative!.&lt;/p&gt;







&lt;h2&gt;
  
  
  Index
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Dependencies&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;React&lt;/li&gt;
&lt;li&gt;React-router-dom&lt;/li&gt;
&lt;li&gt;history&lt;/li&gt;
&lt;li&gt;axios&lt;/li&gt;
&lt;li&gt;react-markdown&lt;/li&gt;
&lt;li&gt;react-spring&lt;/li&gt;
&lt;li&gt;momentjs&lt;/li&gt;
&lt;li&gt;react-loading-skeleton&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Structure&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;components&lt;/li&gt;
&lt;li&gt;routes&lt;/li&gt;
&lt;li&gt;utils&lt;/li&gt;
&lt;/ul&gt;


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







&lt;h2&gt;
  
  
  Dependencies
&lt;/h2&gt;

&lt;p&gt;In the following step, I'll to explain these dependencies and why i use them.&lt;/p&gt;




&lt;h3&gt;
  
  
  React
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Why react?&lt;/strong&gt; i choose react because i think this is te most interesting &lt;em&gt;library&lt;/em&gt; for &lt;strong&gt;JavaScript&lt;/strong&gt;, very popular, you can get a lot of information about this on internet, you really can fell that u can take the controll of the app.&lt;/p&gt;

&lt;p&gt;but react is only a choise, are many other popular &lt;em&gt;framework&lt;/em&gt;/&lt;em&gt;libraries&lt;/em&gt; as &lt;strong&gt;Angular&lt;/strong&gt; or &lt;strong&gt;Vue&lt;/strong&gt;, you can choose whatever you want. you can make the fron-end only with &lt;strong&gt;JavaScript&lt;/strong&gt; and &lt;strong&gt;HTML5&lt;/strong&gt; and &lt;strong&gt;CSS&lt;/strong&gt;, but is good start to think in components and create scalable and easy to mantain applications.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://reactjs.org/"&gt;here&lt;/a&gt; is the official web of &lt;strong&gt;React&lt;/strong&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  React-router-dom
&lt;/h3&gt;

&lt;p&gt;Because &lt;strong&gt;React&lt;/strong&gt; is a &lt;em&gt;library&lt;/em&gt; we need to install all dependencies that are necesaries for our app.&lt;br&gt;
react-router-dom is essencially if we need to work with routes, are other options like &lt;a href="https://www.npmjs.com/package/wouter"&gt;wouter&lt;/a&gt; is more simple and great to small projects, but i use react-router-dom because is more common to see in real projects.&lt;br&gt;
I don't explain how use react-router-dom because &lt;a href="https://reacttraining.com/react-router/web/guides/quick-start"&gt;here&lt;/a&gt; is a guide about this, and we can see a lot of post about how it's work.&lt;/p&gt;


&lt;h3&gt;
  
  
  history
&lt;/h3&gt;

&lt;p&gt;history allow us to navigate between routes without a full page refresh, manage the history stack, navigate, and persist state between sessions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.npmjs.com/package/history"&gt;here&lt;/a&gt; is all about history npm package.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How use history on my project?&lt;/strong&gt; react-router-dom have your own history, you can use this using BrowserRouter, generally we us to see&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;BrowserRouter&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="s2"&gt;react-router-dom&lt;/span&gt;&lt;span class="dl"&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 sentence call the BrowserRouter with your own history;&lt;/p&gt;

&lt;p&gt;in the case you use the external history, you need to use Router, Router is inside of react-router-dom, is like BrowserRouter without a history.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Router&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="s2"&gt;react-router-dom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How install history?&lt;/strong&gt; &lt;code&gt;$ npm install --save history&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How i use history on this project?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;well, a good practice for me, is create a folder with the name &lt;strong&gt;utils&lt;/strong&gt; and inside of this create a file called &lt;em&gt;history.js&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;history.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// First import createBrowserHistory from history&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;createBrowserHistory&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="s2"&gt;history&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Then export the function.&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;createBrowserHistory&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and later in index.js at the src folder.&lt;/p&gt;

&lt;p&gt;index.js - &lt;a href="https://github.com/rhodlib/rhodlib_blog/blob/master/src/index.js"&gt;here&lt;/a&gt; is the full code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Import history from utils&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;history&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./utils/history&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// Import Router from react-router-dom&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;Router&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="s2"&gt;react-router-dom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;StrictMode&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="c1"&gt;// Use history inside of Router&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Router&lt;/span&gt; &lt;span class="nx"&gt;history&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;history&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Router&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/React.StrictMode&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;,
&lt;/span&gt;  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;root&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and this is all, we have history on the app.&lt;/p&gt;




&lt;h3&gt;
  
  
  Axios
&lt;/h3&gt;

&lt;p&gt;As the npm package says, axios is a promise based HTTP client for the browser and node.js.&lt;/p&gt;

&lt;p&gt;we can use &lt;strong&gt;fetch&lt;/strong&gt; to make the requests, but i prefer axios because it make all the work for us and reponse with a JSON, we dont need to make a promise chaining only for that. and i like to work with async/await for asyncronus functions and try/catch for error handling.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.npmjs.com/package/axios"&gt;here&lt;/a&gt; is the link to axios npm package.&lt;/p&gt;




&lt;h3&gt;
  
  
  React-mardown
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.npmjs.com/package/react-markdown"&gt;Here&lt;/a&gt; is the star of the project, this npm package is the solution of all my problems with the markdown. Is a little dangerous save markdown one the backend, because anybody can execute an script, we need to create a purifyDOM, etc. With react-markdown we can save a String in the database with a markdown sintax and the front-end with react-markdown is encharge of transform this sintax on markdown, let's see.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;//Import react-markdown&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ReactMarkdown&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-markdown&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;//Create a component article&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Article&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;textString&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&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;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="c1"&gt;//Use ReactMarkdown with the textString(with markdown sintax) as source&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ReactMarkdown&lt;/span&gt; &lt;span class="nx"&gt;source&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;textString&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Article&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and this is all, we can show strings with markdown sintax stored in the database as Markdown, in the website.&lt;/p&gt;




&lt;h2&gt;
  
  
  React-spring
&lt;/h2&gt;

&lt;p&gt;this is a npm package to make animations and transitions in the components, isn't necessary but is a really interesting&lt;/p&gt;

&lt;p&gt;I'll don't explain much about this because i not use this in the best way, i have a lot to learn, but &lt;a href="https://www.react-spring.io/"&gt;here&lt;/a&gt; is all about react-spring, remember this is not a step-by-step guide, is an article about my first experience about MERN stack.&lt;/p&gt;




&lt;h2&gt;
  
  
  Moment JS
&lt;/h2&gt;

&lt;p&gt;I use moment only for display a Date in the header of each blog, and for this is very simple. obviously are many uses, but for now is right for me.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to install?&lt;/strong&gt; &lt;code&gt;$ npm install --save moment&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to use in my blog?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;src/components/Blogheader/index.js&lt;/code&gt; - &lt;a href="https://github.com/rhodlib/rhodlib_blog/blob/master/src/components/Blogheader/index.js"&gt;here&lt;/a&gt; is the full code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// Import moment&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;moment&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;moment&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// The createdAt prop is type Date storage in the database&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Blogheader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;description&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;createdAt&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h3&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;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h3&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&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;description&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;span&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="c1"&gt;// Use moment, passing a Date and format&lt;/span&gt;
                &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;moment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;createdAt&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;YYYY/MM/DD&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/span&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Blogheader&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  React-loading-skeleton
&lt;/h3&gt;

&lt;p&gt;This is a library to make a skeleton of your content for the view, i normaly prefer a loader. But is usual to see on social media pages, I just used it to test it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.npmjs.com/package/react-loading-skeleton"&gt;here&lt;/a&gt; is all the information about this library&lt;/p&gt;







&lt;h2&gt;
  
  
  Structure
&lt;/h2&gt;

&lt;p&gt;I will explain the structure that i use in the project, only three folders:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;components&lt;/li&gt;
&lt;li&gt;routes&lt;/li&gt;
&lt;li&gt;utils&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and two files &lt;strong&gt;app.js&lt;/strong&gt; and &lt;strong&gt;index.js&lt;/strong&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Components
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/rhodlib/mern_personal_blog/tree/master/client/src/components"&gt;here&lt;/a&gt; are the components folder.&lt;br&gt;
there is four more folders.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;blogheader (It's the component with the title, description and date of creation that you can see when you enter on the website or see an article).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;footer (It's the component with social links and copyright ).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;header (It's the component with Title of the blog and links).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;layout (It's the component where i made the layout is not necesary but is a good practice to me, to keep my components organized).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Routes
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/rhodlib/mern_personal_blog/tree/master/client/src/routes"&gt;here&lt;/a&gt; are the routes of my proyect, there is four folders.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;NewArticles ( this is the route for render the page to create new articles, you can see how this look &lt;a href="https://i.imgur.com/rHJwRxn.png?2"&gt;here&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Article (this route render the article)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Home (this route render the home)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Login (this route render the login page)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Utils
&lt;/h3&gt;

&lt;p&gt;Only have a file called history.js where i create the history.&lt;/p&gt;




&lt;h3&gt;
  
  
  THE END
&lt;/h3&gt;

&lt;p&gt;This is all about the front end of my blog, I hope you find it interesting!.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>My first blog with MERN Stack (Back-end)</title>
      <dc:creator>Rhodlib</dc:creator>
      <pubDate>Mon, 04 May 2020 19:20:50 +0000</pubDate>
      <link>https://dev.to/rhodlib/my-first-blog-with-mern-stack-back-end-3563</link>
      <guid>https://dev.to/rhodlib/my-first-blog-with-mern-stack-back-end-3563</guid>
      <description>&lt;h1&gt;
  
  
  All about my blog: Back-end
&lt;/h1&gt;

&lt;h1&gt;
  
  
  Back-end blog: How?
&lt;/h1&gt;

&lt;p&gt;In this article, I am going to explain how I created the backend for my blog,&lt;br&gt;
what technogies I used and why, this is not a step-by-step guide, it is only a resource if you don't know how to start making your own blog, maybe this can help you on the technologies you need to learn. We have a lot of information on the internet and sometimes it is a little difficult to find a correct answer to our problems.&lt;/p&gt;

&lt;p&gt;All the code of my backend is &lt;a href="https://github.com/rhodlib/mern_personal_blog/tree/master/server"&gt;here&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Index
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Dependencies&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;ExpressJS&lt;/li&gt;
&lt;li&gt;Mongoose&lt;/li&gt;
&lt;li&gt;dotenv&lt;/li&gt;
&lt;li&gt;cors&lt;/li&gt;
&lt;li&gt;validator&lt;/li&gt;
&lt;li&gt;bcryptjs&lt;/li&gt;
&lt;li&gt;jsonwebtoken&lt;/li&gt;
&lt;li&gt;slugify&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Database&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;MongoDB&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Structure&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Controllers&lt;/li&gt;
&lt;li&gt;db&lt;/li&gt;
&lt;li&gt;middlewares&lt;/li&gt;
&lt;li&gt;models&lt;/li&gt;
&lt;li&gt;routes&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Dependencies&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In a few words, I will try to explain these dependencies and why I use them.&lt;/p&gt;


&lt;h3&gt;
  
  
  ExpressJS
&lt;/h3&gt;

&lt;p&gt;The language we use to make this blog is &lt;strong&gt;JavaScript&lt;/strong&gt;, for that reason i use &lt;strong&gt;NodeJS&lt;/strong&gt; for the backend, &lt;strong&gt;NodeJS&lt;/strong&gt; allows us to run &lt;strong&gt;JavaScript&lt;/strong&gt; on the server side.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ExpressJS&lt;/strong&gt; is nothing more than a web &lt;em&gt;framework&lt;/em&gt; for &lt;strong&gt;NodeJS&lt;/strong&gt;, it is robust and has a lot of features to make our lives easier when using &lt;strong&gt;NodeJS&lt;/strong&gt;, for example it allows us to configure a server in 6 lines of code or less.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 1&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="nx"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// 2&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// 3&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Server listening on port 3000&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 4&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt; &lt;span class="c1"&gt;//5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Why ExpressJS?&lt;/strong&gt; Because is the most popular framework for &lt;strong&gt;NodeJS&lt;/strong&gt;, And when it comes to getting a job, it is the most demanded.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Are there other frameworks for NodeJS?&lt;/strong&gt; Sure! we have other awesomes frameworks for &lt;strong&gt;NodeJS&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://hapi.dev/"&gt;Hapi&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://sailsjs.com/"&gt;Sails&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://koajs.com/"&gt;Koa&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://socket.io/"&gt;Socket&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nestjs.com/"&gt;NestJS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;and much more&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;How can install express on my server folder?&lt;/strong&gt; if you has the &lt;strong&gt;package.json&lt;/strong&gt; file on your folder, only need to run the following command&lt;br&gt;
&lt;code&gt;$ npm install --save express&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;It's hard to use?&lt;/strong&gt; No, you really have all the information you need in the official &lt;a href="https://expressjs.com/"&gt;Docs&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Mongoose and MongoDB
&lt;/h3&gt;

&lt;p&gt;As the official website says, &lt;strong&gt;mongoose&lt;/strong&gt; is a elegant &lt;strong&gt;mongodb&lt;/strong&gt; object modeling for &lt;strong&gt;NodeJS&lt;/strong&gt;, what does that mean?.&lt;/p&gt;

&lt;p&gt;Well, &lt;strong&gt;MongoDB&lt;/strong&gt; is a system of databases &lt;strong&gt;NoSQL&lt;/strong&gt;(Not Only SQL),&lt;br&gt;
is a document-based database, we can store information in&lt;br&gt;
&lt;strong&gt;JSON&lt;/strong&gt; (JavaScript Object Notation) format within documents and these documents are saved in collections with an ID provided by &lt;strong&gt;MongoDB&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;But the only way we have to keep organized the data entering and leaving the database is &lt;strong&gt;mongoose&lt;/strong&gt;. Has functions to create a Schema and models.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a Schema?&lt;/strong&gt; Schema is an &lt;strong&gt;Object&lt;/strong&gt; that allows us to declare certain values ​​and generate validations before sending the data to the database. thus allowing us to manage the same structure in all the data that we store.&lt;/p&gt;

&lt;p&gt;this is the schema of an article of my blog , this is how the article is store to the database&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Schema&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="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mongoose&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;postSchema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Schema&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&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="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;required&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="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;markdown&lt;/span&gt;&lt;span class="p"&gt;:&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="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;required&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="na"&gt;createdAt&lt;/span&gt;&lt;span class="p"&gt;:&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="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;now&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;:&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="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;required&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;unique&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="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="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;Post&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Post&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;postSchema&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Post&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;with this schema we create the model that we are going to use to store, save, delete and read the articles in the database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mongoose&lt;/strong&gt; also allows us to connect to the database in a very easy way.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mongoose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mongoose&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;URI&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mongodb://localhost/dbtest&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;mongoose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;connect&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;connection&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mongoose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;once&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;open&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;DB is connected&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Where can get more info about mongoose?&lt;/strong&gt; mongoose has simple and easy-to-read &lt;a href="https://mongoosejs.com/docs/guide.html"&gt;docs&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  dotenv
&lt;/h3&gt;

&lt;p&gt;dotenv is an npm package that allows us to create environment variables. An environment variable is a dynamic variable, it's as simple as writing a variable to an .env file and using it as a reference.&lt;br&gt;
&lt;strong&gt;why do this?&lt;/strong&gt; because we can protect sensitive information or data in the variable (database urls, passwords, tokens) when we upload the files to repositories or servers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How can install dotenv in my project?&lt;/strong&gt; &lt;code&gt;$ npm install --save dotenv&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to configure dotenv to work with de project?&lt;/strong&gt; only need to add a line of code in the top of the index.js.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dotenv&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and then, you can create a .env file in the root of your project. more info about dotnev &lt;a href="https://www.npmjs.com/package/dotenv"&gt;here&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Cors
&lt;/h3&gt;

&lt;p&gt;Cors is simple, I use it because allows me to have two servers at the same time on a different port and to be able to communicate between them, the backend server with nodemon and the frontend server with npm start&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How can install cors?&lt;/strong&gt; &lt;code&gt;$ npm install --save cors&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How usage cors?&lt;/strong&gt; in the index.js of server or wherever you have your app&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cors&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;express&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="nx"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cors&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;more info about cors &lt;a href="https://www.npmjs.com/package/cors"&gt;here&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Validator
&lt;/h3&gt;

&lt;p&gt;validator is a library of string validators and sanitizers&lt;/p&gt;

&lt;p&gt;I use this on the User model, to validate the email property inside the userSchema&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;validator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;validator&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nl"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&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="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;required&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;unique&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;trim&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;lowercase&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;validate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&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;validator&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;value&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="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Email is invalid&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="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;you can see the full code &lt;a href="https://github.com/rhodlib/mern_personal_blog/blob/master/server/src/models/User.js"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How can install validator?&lt;/strong&gt; &lt;code&gt;$ npm install --save validator&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where can learn more about validator?&lt;/strong&gt; you read more &lt;a href="https://www.npmjs.com/package/validator"&gt;here&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  bcryptjs
&lt;/h3&gt;

&lt;p&gt;bcryptjs is an npm package to encrypt, I use this for encrypt passwords, is very easy to use and secure with more than 700k+ downloads per week.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How install bcryptjs?&lt;/strong&gt; &lt;code&gt;$ npm install --save bcryptjs&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How i use bcryptjs?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I use bcrypt in two functions of the "User model", one is creating a method for the user model through the userSchema to encript password.&lt;/p&gt;

&lt;p&gt;User.js - &lt;a href="https://github.com/rhodlib/mern_personal_blog/blob/master/server/src/models/User.js"&gt;Here&lt;/a&gt; is all the code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bcrypt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bcryptjs&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;//Here i created a method for userSchema called encryptPassword&lt;/span&gt;
&lt;span class="nx"&gt;userSchema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;methods&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;encryptPassword&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// get the password&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;bcrypt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hash&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="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 8 is a cicle this been hashed 8 times&lt;/span&gt;
  &lt;span class="c1"&gt;// and then return the password hashed by a function of bcrypt&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And later we need a function to desencrypt the password to validate password and for this I create a static method. static method is a function accesible in the model and not in the userObject&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//Here i created a static method to find credentials and validate password&lt;/span&gt;
&lt;span class="nx"&gt;userSchema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;statics&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;findByCredentials&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&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="nx"&gt;password&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="c1"&gt;//Get email and password&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;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;findOne&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="c1"&gt;//Search by email using the model (findOne is a static method)&lt;/span&gt;
  &lt;span class="k"&gt;if&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="c1"&gt;// If user exist&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isMatch&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;bcrypt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;compare&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="nx"&gt;user&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="c1"&gt;// use a function called compare from bcrypt and compare the password with the user.password in the database.&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;
  
  
  Slugify
&lt;/h3&gt;

&lt;p&gt;Slugify is an npm package to create a slug from a string.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What the f*ck is an slug?&lt;/strong&gt; slug is than simple like this "hello-how-are-you", it's a string with dash instead of spaces.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why i need slug?&lt;/strong&gt; In this blog I use slug like a unique property of each article, using his title as slug, why? because I can search and article for slug and not necesary by ID.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This is te best solution?&lt;/strong&gt; Not, because the best practice is use an ID, but is right for me.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How slug help you?&lt;/strong&gt; It's simple, finding by id, the route in the front-end it's something like this &lt;code&gt;blog.rhodlib.me/article/5468fds1684541sdf18546516s8&lt;/code&gt; this is not estetic, isn't nice to see.&lt;br&gt;
but if find by slug, the route is something like this &lt;code&gt;blog.rhodlib.me/article/all-about-my-blog-backend-how&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How can install slugify?&lt;/strong&gt; &lt;code&gt;$ npm install --save slugify&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How use slugify?&lt;/strong&gt; Is very easy, let's see.&lt;/p&gt;

&lt;p&gt;Post.js &lt;a href="https://github.com/rhodlib/mern_personal_blog/blob/master/server/src/models/Post.js"&gt;here&lt;/a&gt; is all the code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;slugify&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;slugify&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;//the function pre of the postSchema allows us run a function between the validate and the store article on the database&lt;/span&gt;
&lt;span class="nx"&gt;postSchema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pre&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;validate&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;next&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;post&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="k"&gt;if&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;title&lt;/span&gt;&lt;span class="p"&gt;)&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;slug&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;slugify&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;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;lower&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;strict&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="c1"&gt;// We use slugify to create the slug with the title, before save the article in the database&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;next&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;&lt;strong&gt;Where can get more info about slugify?&lt;/strong&gt; you can go &lt;a href="https://www.npmjs.com/package/slugify"&gt;here&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  jsonwebtoken
&lt;/h3&gt;

&lt;p&gt;jsonwebtoken is library to create validation tokens, I use this to validate user when they are connected in the app.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How use JWT in the blog?&lt;/strong&gt; I use jwt in the following way.&lt;/p&gt;

&lt;p&gt;User.js - &lt;a href="https://github.com/rhodlib/mern_personal_blog/blob/master/server/src/models/User.js"&gt;here&lt;/a&gt; is de full code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;jwt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;jsonwebtoken&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// here i created a method for each User called generateAuthToken&lt;/span&gt;
&lt;span class="nx"&gt;userSchema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;methods&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;generateAuthToken&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="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;this&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;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;jwt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sign&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="c1"&gt;// With jwt.sing() we create a token&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;user&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;toString&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="c1"&gt;// I pass the user id in an object&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;AUTHTOKENSTRING&lt;/span&gt; &lt;span class="c1"&gt;// I use an environment variable to encrypt the token with a secret word&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;tokens&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="nx"&gt;tokens&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;concat&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt; &lt;span class="c1"&gt;// And then I put the new token in the user's token array&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;









&lt;h2&gt;
  
  
  &lt;strong&gt;Structure&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I will explain the structure that I use in the project.&lt;/p&gt;

&lt;p&gt;In the server folder I create a src folder in the first level, inside of this folder I create five folder more called:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;controllers&lt;/li&gt;
&lt;li&gt;db&lt;/li&gt;
&lt;li&gt;middlewares&lt;/li&gt;
&lt;li&gt;models&lt;/li&gt;
&lt;li&gt;routes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and two files &lt;strong&gt;app.js&lt;/strong&gt; and &lt;strong&gt;index.js&lt;/strong&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Controllers
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/rhodlib/mern_personal_blog/tree/master/server/src/controllers"&gt;here&lt;/a&gt; I create the controllers of the routes, when a request enters the server, the path executes a function, that function is stored in the controllers.&lt;/p&gt;

&lt;p&gt;auth.controller.js - &lt;a href="https://github.com/rhodlib/mern_personal_blog/blob/master/server/src/controllers/auth.controller.js"&gt;here&lt;/a&gt; is the full code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;authCtrl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;

&lt;span class="nx"&gt;authCtrl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;registerUser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&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="c1"&gt;// Code&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;authCtrl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;loginUser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&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="c1"&gt;// Code&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;authCtrl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  DB
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/rhodlib/mern_personal_blog/tree/master/server/src/db"&gt;here&lt;/a&gt; I create a file called &lt;strong&gt;mongoose.js&lt;/strong&gt; and store my access to database with mongoose.&lt;/p&gt;




&lt;h3&gt;
  
  
  Middlewares
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/rhodlib/mern_personal_blog/tree/master/server/src/middlewares"&gt;here&lt;/a&gt; I create my middlewares, only have one. &lt;strong&gt;auth.js&lt;/strong&gt; where realize the authorization for the login.&lt;/p&gt;




&lt;h3&gt;
  
  
  Models
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/rhodlib/mern_personal_blog/tree/master/server/src/models"&gt;here&lt;/a&gt; I create my two models, with their own schemas.&lt;/p&gt;




&lt;h3&gt;
  
  
  Routes
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/rhodlib/mern_personal_blog/tree/master/server/src/routes"&gt;here&lt;/a&gt; I create the routes for the request. I have three files, within each one the routes are detailed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;auth.routes.js&lt;/li&gt;
&lt;li&gt;post.routes.js&lt;/li&gt;
&lt;li&gt;user.routes.js&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;auth.routes.js - &lt;a href="https://github.com/rhodlib/mern_personal_blog/blob/master/server/src/routes/auth.routes.js"&gt;here&lt;/a&gt; is the full code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;loginUser&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../controllers/auth.controller&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;router&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/api/user/login&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;loginUser&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;









&lt;h2&gt;
  
  
  THE END
&lt;/h2&gt;

&lt;p&gt;And this is all the backend of my blog, I hope you find it interesting and guide you in case you do not know how to start&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>mongodb</category>
    </item>
    <item>
      <title>My first blog with MERN Stack</title>
      <dc:creator>Rhodlib</dc:creator>
      <pubDate>Sun, 03 May 2020 23:29:36 +0000</pubDate>
      <link>https://dev.to/rhodlib/my-first-blog-with-mern-stack-37b4</link>
      <guid>https://dev.to/rhodlib/my-first-blog-with-mern-stack-37b4</guid>
      <description>&lt;h1&gt;
  
  
  All about my blog: Why? What?
&lt;/h1&gt;

&lt;h1&gt;
  
  
  Let's start
&lt;/h1&gt;

&lt;p&gt;This "guide" is for people who want to create a blog from scratch and do not know how to start, it doesn´t contain code or at least for the most part. it´s for guidance only.&lt;/p&gt;

&lt;p&gt;In the following lines I´ll give you the details of the content of this publication, feel comfortable reading it or just go only to the part that interests you, I´ll hope you enjoy it.&lt;/p&gt;







&lt;h2&gt;
  
  
  Index
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Why&lt;/li&gt;
&lt;li&gt;What

&lt;ul&gt;
&lt;li&gt;Front-end&lt;/li&gt;
&lt;li&gt;Back-end&lt;/li&gt;
&lt;li&gt;Database&lt;/li&gt;
&lt;li&gt;Utils&lt;/li&gt;
&lt;li&gt;Styling&lt;/li&gt;
&lt;/ul&gt;


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







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

&lt;p&gt;I made a blog because I think it is the best way to practice. I used my knowledge of front-end and back-end.&lt;/p&gt;

&lt;p&gt;A blog is a good quick-source in case you have to solve problems. it´s information in your own words. It´s like a notebook, but you can share that information with other people and learn together. Sharing information about programming with other people is what makes it a beautiful environment.&lt;/p&gt;

&lt;p&gt;This blog was based on &lt;strong&gt;Markdown&lt;/strong&gt;,because i love it and in think it´s simple elegant and very clear. it has a beautifull sintax.&lt;/p&gt;

&lt;p&gt;More info about &lt;strong&gt;markdown&lt;/strong&gt; &lt;a href="https://en.wikipedia.org/wiki/Markdown"&gt;here&lt;/a&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  What technologies you use for this blog ?
&lt;/h2&gt;

&lt;p&gt;Just like most internet pages this blot it´s based on a front-end a back-end and a database. I dicided to use a stack called  MERN (MongoDB, Express, React, Node) in this particular case because it uses javascript on the client and server side.&lt;/p&gt;




&lt;h3&gt;
  
  
  Front-end
&lt;/h3&gt;

&lt;p&gt;The front-end is the part of a website with which users interact. all you can see when you browse the internet,from fonts and colors to drop-down menus and sliders. As much as simple it seems,you may have a lot of functionality and complex code.&lt;/p&gt;

&lt;p&gt;For the &lt;strong&gt;front-end&lt;/strong&gt; of the blog i prefer the following technologies.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://reactjs.org/"&gt;react&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/react-router-dom"&gt;react-router-dom&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/history"&gt;history&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/axios"&gt;axios&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/react-markdown"&gt;react-markdown&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/react-spring"&gt;react-spring&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://momentjs.com/"&gt;momentjs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/react-loading-skeleton"&gt;react-loading-skeleton&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It seems a lot of things, but each of the dependencies are use on something in particular.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blog.rhodlib.me/article/all-about-my-blog-front-end-how"&gt;Link to front-end: how?&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Back-end
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;back-end&lt;/strong&gt; consist of a server an application and a database. . it´s the data access layer of a software or any other device, which is not directly accessible by users,also contains the logic of the application that handles said data.&lt;/p&gt;

&lt;p&gt;For &lt;strong&gt;the back-end&lt;/strong&gt; of the blog I choose the following technologies&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://nodejs.org/en/"&gt;NodeJS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://expressjs.com/"&gt;ExpressJS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://mongoosejs.com/"&gt;Mongoose&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/dotenv"&gt;dotenv&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/cors"&gt;cors&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/validator"&gt;validator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/bcryptjs"&gt;bcryptjs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/jsonwebtoken"&gt;jsonwebtoken&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/slugify"&gt;slugify&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Database
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;database&lt;/strong&gt; is where we store all the data, in this case we storage users and articles.&lt;/p&gt;

&lt;p&gt;I use &lt;strong&gt;MongoDB&lt;/strong&gt; for my blog´s database.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.mongodb.com/"&gt;MongoDB&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://blog.rhodlib.me/article/all-about-my-blog-back-end-how"&gt;Link to back-end: how?&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Utils
&lt;/h3&gt;

&lt;p&gt;The utils are the tools I use to develop, I don't need an article to explain them, because they all have their own documentation and are basic development tools.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://code.visualstudio.com/"&gt;VScode&lt;/a&gt;
// Visual Studio Code&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.google.com/intl/es-419/chrome/"&gt;Chrome&lt;/a&gt;
// Web browser&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://insomnia.rest/"&gt;Insomnia&lt;/a&gt;
// Desktop API client for REST simil to Postman&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/nodemon"&gt;nodemon&lt;/a&gt;
// npm package, it is used to keep the local server running&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Styling
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://prettier.io/"&gt;prettier&lt;/a&gt;
// Tool for styling the code in the code editor&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://kognise.github.io/water.css/"&gt;water.css&lt;/a&gt;
// Is a collection of styles to make simple website, this stylizes the html semantics, It's simple and beautiful.&lt;/li&gt;
&lt;/ul&gt;

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