<?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: Emmy | Pixi</title>
    <description>The latest articles on DEV Community by Emmy | Pixi (@thecodepixi).</description>
    <link>https://dev.to/thecodepixi</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%2F119282%2Fb8b39c6f-53a8-4019-88a3-c1d0a271f42e.jpg</url>
      <title>DEV Community: Emmy | Pixi</title>
      <link>https://dev.to/thecodepixi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/thecodepixi"/>
    <language>en</language>
    <item>
      <title>What is a "Closure" in JavaScript?</title>
      <dc:creator>Emmy | Pixi</dc:creator>
      <pubDate>Fri, 24 Jul 2020 20:14:59 +0000</pubDate>
      <link>https://dev.to/thecodepixi/what-is-a-closure-in-javascript-4h6e</link>
      <guid>https://dev.to/thecodepixi/what-is-a-closure-in-javascript-4h6e</guid>
      <description>&lt;h2&gt;
  
  
  What is a "closure"?
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;closure&lt;/strong&gt; is the combination of a function enclosed with references to its surrounding state (&lt;em&gt;lexical environment&lt;/em&gt;). It gives you access to an outer function's scope or environment from an inner function.&lt;/p&gt;

&lt;p&gt;Consider the following code snippet:&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;function&lt;/span&gt; &lt;span class="nx"&gt;outerFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;innerVar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I'm inside outerFunction&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="nx"&gt;innerFunction&lt;/span&gt;&lt;span class="p"&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="nx"&gt;log&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="nx"&gt;innerVar&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;, but I can be accessed from innerFunction too!`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;innerFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;outerFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// &amp;gt; "I'm inside outerFunction, but I can be accessed from innerFunction too!"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Lexical Scope/Environment
&lt;/h3&gt;

&lt;p&gt;In the above code snippet, &lt;code&gt;outerFunction&lt;/code&gt; creates a variable called &lt;code&gt;innerVar&lt;/code&gt;, and a function called &lt;code&gt;innerFunction&lt;/code&gt;. The &lt;code&gt;innerFunction&lt;/code&gt; function is &lt;strong&gt;enclosed&lt;/strong&gt; inside, and is only available within, &lt;code&gt;outerFunction&lt;/code&gt;. &lt;code&gt;innerFunction&lt;/code&gt; has no local variables of its own, but is able to access &lt;code&gt;innerVar&lt;/code&gt; because they are both within the &lt;em&gt;lexical scope&lt;/em&gt; of &lt;code&gt;outerFunction&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Closure
&lt;/h3&gt;

&lt;p&gt;In the initial code snippet, we called &lt;code&gt;innerFunction&lt;/code&gt; immediately after declaring it. But what if we &lt;code&gt;return&lt;/code&gt; the inner function instead?&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;function&lt;/span&gt; &lt;span class="nx"&gt;outside&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Pixi&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="nx"&gt;inside&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myName&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;inside&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;insideOutside&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;outside&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;insideOutside&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we run this code, we'll get an alert with my name. &lt;em&gt;But why?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The reason this works is because functions in JavaScript form &lt;strong&gt;closures&lt;/strong&gt;. A closure is a combination of a function and the &lt;em&gt;lexical scope&lt;/em&gt; within which the function was declared.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;insideOutside&lt;/code&gt; becomes a reference to an instance of our &lt;code&gt;inside&lt;/code&gt; function when &lt;code&gt;outside&lt;/code&gt; is run. This instance of &lt;code&gt;inside&lt;/code&gt; maintains a reference to its &lt;em&gt;lexical scope&lt;/em&gt;, which allows it to maintain its reference to the &lt;code&gt;myName&lt;/code&gt; variable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Passing Arguments
&lt;/h3&gt;

&lt;p&gt;We can use closures to our advantage in creating enclosed functions that accept arguments.&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="cm"&gt;/* we create a function that accepts one argument, 
and returns a function that also accepts one argument, 
and utilizes both arguments... */&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;makeMultiplier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&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="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;y&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;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;y&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="cm"&gt;/* we can call the outer function 
and assign it to a variable */&lt;/span&gt; 
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;multiplyBy2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;makeMultiplier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;multiplyBy5&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;makeMultiplier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;multiplyBy2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// 6&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="nx"&gt;multiplyBy5&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// 15&lt;/span&gt;

&lt;span class="cm"&gt;/* we can also use argument chaining to call 
both functions at once */&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="nx"&gt;makeMultiplier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// 6&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="nx"&gt;makeMultiplier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// 15&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our new &lt;code&gt;makeMultiplier&lt;/code&gt; function gives us the ability to &lt;strong&gt;create more functions&lt;/strong&gt; and then use those functions later.&lt;/p&gt;

&lt;p&gt;When we create &lt;code&gt;multiplyBy2&lt;/code&gt;, the reference to &lt;code&gt;x = 2&lt;/code&gt; becomes a part of the functions &lt;em&gt;lexical scope&lt;/em&gt;. We can then use this function to multiply other numbers by 2. The same is true for &lt;code&gt;multiplyBy5&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;When we use argument chaining, we simply call the inner function immediately by passing an argument to &lt;code&gt;makeMultiplier&lt;/code&gt; and immediately passing an argument to the function which it returns.&lt;/p&gt;

&lt;h2&gt;
  
  
  Want to learn more about scope in JavaScript?
&lt;/h2&gt;

&lt;p&gt;Check out &lt;a href="https://dev.to/thecodepixi/hoist-your-vars-variable-hoisting-in-javascript-2f42"&gt;my previous post on scope and variable hoisting&lt;/a&gt; and let me know if you still have any questions! It might inspire a future blog post!&lt;/p&gt;

&lt;p&gt;xx - Emily / TheCodePixi&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;External Resources:&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures"&gt;MDN Closure Docs&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>beginners</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>How To: Create A Rainbow Link Hover Effect</title>
      <dc:creator>Emmy | Pixi</dc:creator>
      <pubDate>Fri, 17 Jul 2020 22:25:31 +0000</pubDate>
      <link>https://dev.to/thecodepixi/how-to-create-a-link-rainbow-hover-effect-45of</link>
      <guid>https://dev.to/thecodepixi/how-to-create-a-link-rainbow-hover-effect-45of</guid>
      <description>&lt;p&gt;So, typically I try to write pretty long, in-depth articles and tutorials. This week I &lt;em&gt;do not&lt;/em&gt; have the energy, so we're doing a quick tutorial on how I created a rainbow hover effect for the links in the forth-coming redesign of my website and blog. This is also my first tutorial on anything CSS related!   🎉 So, let's get into it...&lt;/p&gt;

&lt;h2&gt;
  
  
  First, let's talk &lt;code&gt;a&lt;/code&gt; tags:
&lt;/h2&gt;

&lt;p&gt;As you probably already know, &lt;code&gt;a&lt;/code&gt; tags are what we use to create both internal and external links on a webpage. We can target and add effects to links when we hover our cursor over them by using the &lt;code&gt;:hover&lt;/code&gt; selector.&lt;/p&gt;

&lt;p&gt;For example, let's say on my site, I have all of my &lt;code&gt;a&lt;/code&gt; tags set to be &lt;code&gt;blue&lt;/code&gt; by default:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;a&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&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 I want them to be &lt;code&gt;red&lt;/code&gt; when they're hovered over. To accomplish that, we can simply do the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&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 will produce the effect demonstrated below:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/TheCodePixi/embed/dyGQMoq?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Great! We can handle a basic &lt;code&gt;a&lt;/code&gt; tag hover. Now how do we get it to be a rainbow? 🤔&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a &lt;code&gt;linear-gradient&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;In order to create the rainbow effect we're looking for, what we need to do is apply a &lt;code&gt;linear-gradient&lt;/code&gt; background to our text, and then use something called a &lt;code&gt;background-clip&lt;/code&gt; to only apply that gradient to the text of our link.&lt;/p&gt;

&lt;p&gt;First, let's create that gradient:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;a&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;black&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;linear-gradient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;90deg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;orange&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;yellow&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;purple&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;The &lt;code&gt;linear-gradient&lt;/code&gt; background option takes a few arguments:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;First, the angle you want the direction of your gradient to be. Here, I've chosen &lt;code&gt;90deg&lt;/code&gt; so the gradient will go in order from left to right. &lt;em&gt;(if you do not include this argument the gradient will be applied from top to bottom)&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then, you can list any number of colors you want to include in your gradient. I've chosen the full rainbow spectrum, but you could really choose any colors you like, and use any color format (CSS color names, hex color codes, HSL, RGB, etc).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Try this out and see what happens.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Oops! That's not what we were expecting...&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you tried this out, you'll notice that the gradient is, as you might expect, applied to the entire background of our text.&lt;/p&gt;

&lt;h2&gt;
  
  
  This is where the &lt;code&gt;background-clip&lt;/code&gt; comes in...
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;a&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;black&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;linear-gradient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;90deg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;orange&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;yellow&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;purple&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;background-clip&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;text&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;-webkit-background-clip&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;text&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;Using &lt;code&gt;background-clip&lt;/code&gt; tells your CSS exactly where you want to apply your background. Setting this option to &lt;code&gt;text&lt;/code&gt; tells our CSS we want the background only applied to the text inside of the element we're targeting.&lt;/p&gt;

&lt;p&gt;You can &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/background-clip"&gt;read more about &lt;code&gt;background-clip&lt;/code&gt; on MDN&lt;/a&gt;, but keep in mind that &lt;code&gt;background-clip: text&lt;/code&gt; &lt;strong&gt;is not widely supported yet&lt;/strong&gt;. This effect will work best in Firefox, Edge, and Chrome, as long as you include the &lt;code&gt;-webkit-background-clip&lt;/code&gt; option. This effect &lt;em&gt;will not work&lt;/em&gt; in IE, which I'm sure comes as no surprise.&lt;/p&gt;

&lt;p&gt;Now that we've added this to our CSS you might be thinking that it's not working. Your text will appear as whatever color you've specified in your CSS (&lt;em&gt;here I've used black&lt;/em&gt;) and that's a &lt;em&gt;good thing&lt;/em&gt;!&lt;/p&gt;

&lt;p&gt;There's one more step...&lt;/p&gt;

&lt;p&gt;Now, when we we &lt;code&gt;:hover&lt;/code&gt; over our links, we want to make our link text &lt;code&gt;transparent&lt;/code&gt;, which will allow our background gradient to show through. I'm also going to add a slight transition effect, because I like the look of the gradient slowly fading in...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;transparent&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;500ms&lt;/span&gt; &lt;span class="n"&gt;ease&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;Here's the final effect:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/TheCodePixi/embed/BajGKRN?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;And that's it! We have a nice rainbow gradient hover effect on our links! 🎉&lt;/p&gt;

&lt;p&gt;I really enjoy adding little touches like this to my projects because it just adds a fun little flair and some personality, plus I especially enjoying finding way to incorporate rainbows into anything I can.&lt;/p&gt;

&lt;p&gt;Let me know if you try this out, and happy hovering!&lt;/p&gt;

&lt;p&gt;xx -Emily / TheCodePixi&lt;/p&gt;

</description>
      <category>css</category>
      <category>html</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Comparing Code: Ruby, JavaScript, and Java Walk Into a Bar...</title>
      <dc:creator>Emmy | Pixi</dc:creator>
      <pubDate>Sat, 11 Jul 2020 00:31:01 +0000</pubDate>
      <link>https://dev.to/thecodepixi/ruby-javascript-and-java-walk-into-a-bar-2103</link>
      <guid>https://dev.to/thecodepixi/ruby-javascript-and-java-walk-into-a-bar-2103</guid>
      <description>&lt;p&gt;After nearly two years of studying and learning, I was finally starting to not feel so much like a "beginner" or a "newbie" at programming.&lt;br&gt;
I've built REST APIs in Rails and Express, I've built fullstack applications using modern JavaScript frameworks, and I've queried databases using (various flavors of) SQL and GraphQL...&lt;/p&gt;

&lt;h3&gt;
  
  
  &amp;gt; &lt;strong&gt;And then I decided to learn Java&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Suddenly, I'm a newbie again. Not quite a complete beginner, but definitely green, and getting started with Java has been an exciting experience.&lt;br&gt;
Java feels like what I always &lt;em&gt;imagined&lt;/em&gt; programming to be, moreso than Ruby or JavaScript ever did. Writing in a strictly typed language has been almost entirely new for me, outside of a little bit of dabbling with TypeScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  My Learning Resources
&lt;/h2&gt;

&lt;p&gt;So far the thing that has surprised me the most about Java is how little I hate it. That might sound weird, but with the reactions I've received to telling people "Hey, I'm learning Java!", you'd think I'd decided to sell my first born child's soul to the Computer Science devil or something. But it actually hasn't been too bad, too big of a departure from what I already know, or too big of a barrier to entry.&lt;/p&gt;

&lt;p&gt;The particularly excellent thing about Java is that because it is so ubiquitous, and so pervasive and popular, there are a wealth of resources available for you to learn it, and significant number of them are free or very affordable.&lt;/p&gt;

&lt;p&gt;The two resources that I've personally been using are the wonderful &lt;a href="https://testautomationu.applitools.com/java-programming-course/"&gt;Java Programming course by Angie Jones at Test Automation U&lt;/a&gt;, and the &lt;a href="https://hyperskill.org/curriculum"&gt;Java Developer learning path on JetBrains Academy&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Angie's Java Programming course is &lt;em&gt;completely free&lt;/em&gt; and perfect for people who want to get up to speed quickly. She covers all of the Java essentials, with quizzes and homework assignments built in along the way so you can test your learning as you go.&lt;/p&gt;

&lt;p&gt;The JetBrain's Academy program is surprisingly affordable, and a better option for people who prefer a more regimented course, and are starting from absolute zero. Even if you have no prior programming experience, you can tailor the JetBrain's curriculum to your needs. And if you have prior experience from learning another language, you're given the option to skip sections of the curriculum you're already comfortable with.&lt;/p&gt;

&lt;h2&gt;
  
  
  OK, now let's get to the tutorial ...
&lt;/h2&gt;

&lt;p&gt;What I've decided to do with this tutorial is to show you how to code something fairly basic, and compare the solutions side by side in Ruby, JavaScript and Java. I like doing this when I'm learning (coding the same thing I'm learning in the languages I'm already comfortable with) because it's a good exercise to see how things &lt;em&gt;translate&lt;/em&gt;. Just like how if you were translating a sentence into another language, you'd already want to know how the sentence should be structured in your native language, before trying to do the translation.&lt;/p&gt;

&lt;p&gt;So today we're going to write a short program to calculate the quantities we need to brew a particular amount of coffee.&lt;br&gt;
&lt;em&gt;(Get it? Java? JetBrains made this joke too, don't @ me, lol)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What we know we need:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;20g of coffee per cup&lt;/li&gt;
&lt;li&gt;14 oz of water per cup&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We're going to keep it to just those two variables, to keep things as simple as possible. Our only unknown variable is the number of cups of coffee that we want to make. That will be what we pass in to the function/method as a parameter/argument.&lt;/p&gt;

&lt;p&gt;Let's say we're having some friends over, so want to make 5 cups of coffee.&lt;/p&gt;

&lt;h2&gt;
  
  
  Here's how we could write this in Ruby...
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# main.rb&lt;/span&gt;

&lt;span class="c1"&gt;# set up a coffee maker class&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CoffeeMaker&lt;/span&gt;

  &lt;span class="c1"&gt;# variables for the amount of coffee and water per cup can only be read&lt;/span&gt;
  &lt;span class="nb"&gt;attr_reader&lt;/span&gt; &lt;span class="ss"&gt;:coffeeGramsPerCup&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:waterOzPerCup&lt;/span&gt;
  &lt;span class="c1"&gt;# cupsToMake can be altered as needed&lt;/span&gt;
  &lt;span class="nb"&gt;attr_accessor&lt;/span&gt; &lt;span class="ss"&gt;:cupsToMake&lt;/span&gt;

  &lt;span class="c1"&gt;# class initializer takes in the quantity of coffee to make&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;initialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cupsToMake&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="vi"&gt;@coffeeGramsPerCup&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;
    &lt;span class="vi"&gt;@waterOzPerCup&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;
    &lt;span class="vi"&gt;@cupsToMake&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cupsToMake&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="c1"&gt;# a method that calculates the quantities needed and outputs a string to the console&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;makeCoffee&lt;/span&gt;
    &lt;span class="n"&gt;waterNeeded&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="vi"&gt;@waterOzPerCup&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="vi"&gt;@cupsToMake&lt;/span&gt;
    &lt;span class="n"&gt;coffeeNeeded&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="vi"&gt;@coffeeGramsPerCup&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="vi"&gt;@cupsToMake&lt;/span&gt;

    &lt;span class="nb"&gt;print&lt;/span&gt; &lt;span class="s2"&gt;"You will need &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;waterNeeded&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; oz of water and &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;coffeeNeeded&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; grams of coffee beans &lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;to make &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="vi"&gt;@cupsToMake&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; cups of coffee."&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="c1"&gt;# initialize a coffee maker and call the makeCoffee method&lt;/span&gt;
&lt;span class="c1"&gt;# passing it the quantity of coffee we'd like to make&lt;/span&gt;
&lt;span class="n"&gt;myOrder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;CoffeeMaker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;myOrder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;makeCoffee&lt;/span&gt;

&lt;span class="c1"&gt;# Console Output:&lt;/span&gt;
&lt;span class="c1"&gt;# &amp;gt; You will need 70 oz of water and 100 grams of coffee to make 5 cups of coffee.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ruby is a &lt;em&gt;great&lt;/em&gt; candidate for comparison to Java, because it is also an &lt;strong&gt;Object Oriented&lt;/strong&gt; Language, and lets us handle things in very similar ways.&lt;/p&gt;

&lt;p&gt;In the example above, we've created a class called &lt;code&gt;CoffeeMaker&lt;/code&gt;, and given it class variables to handle what we know already (the amount of coffee and water needed per cup), and we &lt;em&gt;initialize&lt;/em&gt; the instance of the class with the number of cups of coffee we'd like to make. Then, we call the method &lt;code&gt;makeCoffee&lt;/code&gt; which calculates our coffee and water needs and outputs the result to the console.&lt;/p&gt;

&lt;h2&gt;
  
  
  And now we can try it in JavaScript...
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// index.js&lt;/span&gt;

&lt;span class="c1"&gt;// global variables for coffee and water&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;COFFEE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&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;WATER&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// create our coffeeMaker function, where n is the requested number of cups&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;coffeeMaker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;coffeeNeeded&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;COFFEE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;waterNeeded&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;WATER&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s2"&gt;`You will need &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;waterNeeded&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; oz. of water and &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;coffeeNeeded&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; grams of coffee, to make &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; cups of coffee.`&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// call our coffeeMaker function&lt;/span&gt;
&lt;span class="nx"&gt;coffeeMaker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Console Output:&lt;/span&gt;
&lt;span class="c1"&gt;// &amp;gt; You will need 70 oz of water and 100 grams of coffee to make 5 cups of coffee.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That &lt;em&gt;looks&lt;/em&gt; little more streamlined! Since JavaScript is not an Object Oriented language by default, we can simply declare some global variables, write a function, call the function, and call it a day. We could also call this function from &lt;em&gt;anywhere&lt;/em&gt; we want to as long as we &lt;code&gt;export&lt;/code&gt; it and &lt;code&gt;require&lt;/code&gt; the file containing it, regardless of whether what we're writing really has anything to do with making coffee.&lt;/p&gt;

&lt;p&gt;There are object oriented approaches you could use in JavaScript, but I decided to show the functional version here, because there are always trade-offs to each methodology.&lt;/p&gt;

&lt;p&gt;In the Ruby version, we created a variable that contains our initialization of our coffee order, &lt;code&gt;myOrder&lt;/code&gt;. If we ended up wanting a different quantity of coffee, we can simply reassign the value of &lt;code&gt;cupsToMake&lt;/code&gt; by calling the setter method on &lt;code&gt;myOrder&lt;/code&gt;. Then we can &lt;code&gt;makeCoffee&lt;/code&gt; again, without initializing a new CoffeeMaker.&lt;/p&gt;

&lt;h2&gt;
  
  
  And finally, here's how I've written this in Java...
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CoffeeMaker&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

  &lt;span class="c1"&gt;// private class 'fields', so they cannot be altered&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;coffeePerCup&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;waterPerCup&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;// cupsToMake is a 'public' variable so we get a 'setter' method&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;cupsToMake&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// initialize class with number of cups of coffee requested&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;CoffeeMaker&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;cupsToMake&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;cupsToMake&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cupsToMake&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// method to make coffee&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;makeCoffee&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;coffeeNeeded&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;coffeePerCup&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;cupsToMake&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;waterNeeded&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;waterPerCup&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;cupsToMake&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"You will need "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;waterNeeded&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" oz. of water and "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;coffeeNeeded&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" grams of coffee beans to make "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;cupsToMake&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" cups of coffee."&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Yep! we're initializing an instance of the class inside the class itself!&lt;/span&gt;
        &lt;span class="nc"&gt;CoffeeMaker&lt;/span&gt; &lt;span class="n"&gt;myOrder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;CoffeeMaker&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;myOrder&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;makeCoffee&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

        &lt;span class="c1"&gt;// Console Output&lt;/span&gt;
        &lt;span class="c1"&gt;// &amp;gt; You will need 70 oz of water and 100 grams of coffee to make 5 cups of coffee.&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This approach is fairly similar to Ruby, and I &lt;em&gt;hope&lt;/em&gt; I wrote them in a way that you're able to see the similarities between the two blocks of code.&lt;/p&gt;

&lt;p&gt;We have some class level variables that are constant and immutable (there is no 'setter' method to alter them), and we have our &lt;code&gt;public&lt;/code&gt; &lt;code&gt;cupsToMake&lt;/code&gt; variable that can be updated as needed.&lt;/p&gt;

&lt;p&gt;We create a method called &lt;code&gt;makeCoffee&lt;/code&gt; that calculates the quantities, and outputs the results, that we can call on any instance of our &lt;code&gt;CoffeeMaker&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The benefits of the Object Oriented approach are the same across OO languages. I find reusability of classes, and instances of classes, appealing. I enjoy being able to say "OK here's my instance of &lt;em&gt;CLASS&lt;/em&gt; and now I'm going to do &lt;em&gt;X Y Z&lt;/em&gt; to &lt;em&gt;only&lt;/em&gt; this instance."&lt;/p&gt;




&lt;p&gt;I hope this weird romp through some Ruby/JavaScript/Java code was fun for someone other than me! I hope it encourages some people who might be wary of Java to give it a try. It's not a scary as it first seems, and can be really approachable when you choose the right learning tools.&lt;/p&gt;

&lt;p&gt;And if you're a Java developer looking at this and ripping their hair out, &lt;strong&gt;PLEASE LET ME KNOW!&lt;/strong&gt; My goal is simply to keep improving, so I'll take any tips or knowhow you're willing to throw my way.&lt;/p&gt;

&lt;p&gt;xx&lt;/p&gt;

&lt;p&gt;-Emily / TheCodePixi&lt;/p&gt;

&lt;p&gt;P.S. You can follow me on &lt;a href="https://twitter.com/thecodepixi"&gt;Twitter&lt;/a&gt; and read more of my writing &lt;a href="https://thecodepixi.dev/blog"&gt;on my blog&lt;/a&gt; &lt;/p&gt;

</description>
      <category>java</category>
      <category>javascript</category>
      <category>ruby</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Fullstack Project Planning</title>
      <dc:creator>Emmy | Pixi</dc:creator>
      <pubDate>Sat, 04 Jul 2020 03:31:45 +0000</pubDate>
      <link>https://dev.to/thecodepixi/fullstack-project-planning-3jml</link>
      <guid>https://dev.to/thecodepixi/fullstack-project-planning-3jml</guid>
      <description>&lt;p&gt;So, this week I meant to put up the next post in my MERN stack project series, but I realized that I was leaving out a &lt;strong&gt;huge&lt;/strong&gt; part of the project-process by not talking about proper project planning. For most of my projects, especially recently, I've been following a planning process that helps me breakdown the project into component parts that help me build more efficiently.&lt;/p&gt;

&lt;h3&gt;
  
  
  Here's a basic project planning breakdown:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Scope&lt;/li&gt;
&lt;li&gt;Database Modeling&lt;/li&gt;
&lt;li&gt;API Endpoint Planning&lt;/li&gt;
&lt;li&gt;Backend Build&lt;/li&gt;
&lt;li&gt;Backend Testing&lt;/li&gt;
&lt;li&gt;Wireframing/Sketches&lt;/li&gt;
&lt;li&gt;Component Planning&lt;/li&gt;
&lt;li&gt;Frontend Build&lt;/li&gt;
&lt;li&gt;Frontend Testing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Below are the questions and elements of each part of the process...&lt;/p&gt;




&lt;h2&gt;
  
  
  Scope
&lt;/h2&gt;

&lt;p&gt;This step simply involves planning the scope of the project in question. Are you building both a backend and frontend? Do you need to account for user authentication? Will you be using any external/third-party APIs?&lt;/p&gt;

&lt;h2&gt;
  
  
  Database Modeling
&lt;/h2&gt;

&lt;p&gt;If you've decided to build a fullstack project, what database will you be using? What database models will you need? If you're using a relational database, what relationships do you need between models? If you're using MongoDB, do you have a cluster available to put your collection in?&lt;/p&gt;

&lt;h2&gt;
  
  
  API Endpoint Planning
&lt;/h2&gt;

&lt;p&gt;You've got your database set up, so now it's time to plan out your endpoints! Do you need full CRUD endpoints for every model? Are you planning to handle query parameters with your API? Which endpoints will be public, and which will be protected? How will you protect those endpoints that aren't publicly accessible?&lt;/p&gt;

&lt;h2&gt;
  
  
  Backend Build
&lt;/h2&gt;

&lt;p&gt;Time to build!! Are you using Rails, Express, Django, or something else? Where will you host your API?&lt;/p&gt;

&lt;h2&gt;
  
  
  Backend Testing
&lt;/h2&gt;

&lt;p&gt;Test your code, folks! Build out tests as you go with your testing framework/tool of choice. I also really love using something like Postwoman/Postman or Insomnia for manually testing API endpoints. They let you mock your API calls to make sure your responses are coming through as expected.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wireframing / Sketches
&lt;/h2&gt;

&lt;p&gt;We made it to the frontend design! 🎉&lt;br&gt;
This step is &lt;em&gt;crucial&lt;/em&gt; and is the step I most frequently skip and I &lt;em&gt;always&lt;/em&gt; regret it.&lt;br&gt;
Even if you don't consider yourself a designer, sketching out a basic concept layout makes the coding process so much easier. This step is even easier if you're using a UI library like Material UI or Bootstrap, because you can plan out which components/classes you'll use ahead of time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Component Planning
&lt;/h2&gt;

&lt;p&gt;If you're using a component based framework like React, it's a really good idea to look at your sketches and break them down into components. Where are your containers? Which components maintain state? Can you create a "single source of truth" for your app to keep your state in check? Planning this out ahead of time will save you &lt;em&gt;so much&lt;/em&gt; frustration later on.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frontend Build
&lt;/h2&gt;

&lt;p&gt;We did it, y'all! We made it to the frontend build process!&lt;br&gt;
Even though this is ostensibly the last step, it could certainly be one of the longest.&lt;br&gt;
Do you know which frameworks or CSS pre-processors you'll use, if any? Do you have your fonts, and colors, and style elements chosen? Are you using them consistently? Are you designing mobile-first and for accessibility? If not, you should be!&lt;/p&gt;

&lt;h2&gt;
  
  
  Frontend Testing
&lt;/h2&gt;

&lt;p&gt;This step is coupled with the prior build test. Write your tests as you go, and make sure you're covering edge cases appropriately. How are you handling errors from a UI perspective? Does your app or site fail well? If not, how can you better handle errors for your users?&lt;/p&gt;

&lt;h2&gt;
  
  
  User Testing
&lt;/h2&gt;

&lt;p&gt;If you want to be really ambitious, and don't mind sharing your project with others, it's a great idea to get some opinions from users. They might find edge cases you missed, or have suggestions for improving your app that you might be too close to the project to see on your own.&lt;/p&gt;




&lt;p&gt;For beginners working on their first portfolio project, this list can feel really long and really intimidating, but fear not! My favorite thing about this list, and this process, is that each step is relatively self contained, and each one builds on the last. And you don't necessarily have to have &lt;em&gt;everything&lt;/em&gt; planned ahead of time. Maybe you'll plan out the database and API endpoints, and start on your backend build, before you really start thinking much about your front end. Or maybe you'll design a really beautiful frontend mockup and then plan out a backend to fit into that design.&lt;/p&gt;

&lt;p&gt;Either way, planning is your friend! I've only really recently gotten a handle on proper project planning and it's made the process so much more efficient.&lt;/p&gt;

&lt;p&gt;I hope this list helps you get your next project finished just a little bit more efficiently!&lt;/p&gt;

&lt;p&gt;xx&lt;br&gt;
Emily / TheCodePixi&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This article was originally posted on &lt;a href="https://thecodepixi.dev/blog/planning-a-project/"&gt;TheCodePixi.dev/blog&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>productivity</category>
      <category>codenewbie</category>
      <category>beginners</category>
    </item>
    <item>
      <title>REST API with CRUD using Express and Mongoose</title>
      <dc:creator>Emmy | Pixi</dc:creator>
      <pubDate>Sun, 21 Jun 2020 00:01:35 +0000</pubDate>
      <link>https://dev.to/thecodepixi/rest-api-with-crud-using-express-and-mongoose-d7h</link>
      <guid>https://dev.to/thecodepixi/rest-api-with-crud-using-express-and-mongoose-d7h</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Previously in this series we walked through &lt;a href="https://thecodepixi.dev/blog/your-first-express-server"&gt;setting up your first Express server&lt;/a&gt;, and then setting up &lt;a href="https://thecodepixi.dev/blog/setting-up-an-express-api-with-mongoose"&gt;the beginnings of an Express API&lt;/a&gt; with Mongoose/MongoDB data storage.&lt;/p&gt;

&lt;p&gt;This post will jump off exactly where we left of in &lt;a href="https://thecodepixi.dev/blog/setting-up-an-express-api-with-mongoose"&gt;the previous post&lt;/a&gt;, so if you haven't been following along, I recommend at least going back and reading through that post first.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;If you prefer to jump straight into the code, you can find that &lt;a href="https://github.com/thecodepixi/puppy-rest-api"&gt;here&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;And if you prefer to learn by watching video tutorials, you can watch the live stream of this entire API build &lt;a href="https://www.twitch.tv/videos/648121558"&gt;here&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started...
&lt;/h2&gt;

&lt;p&gt;In the last installment in this series, we left off with having just completed our first Mongoose Schema and database Model. This means we're ready to start building our router and our API endpoints!&lt;/p&gt;

&lt;p&gt;The first thing we need to do is create a new folder in the top level directory of our project called &lt;code&gt;routers&lt;/code&gt; and put a file inside that folder called &lt;code&gt;puppy.js&lt;/code&gt;&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="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;routers
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;puppy.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we want to tell our Express server (in &lt;code&gt;index.js&lt;/code&gt;) that we want to &lt;code&gt;use(puppy.js)&lt;/code&gt; for our Puppy routing endpoints.&lt;/p&gt;

&lt;p&gt;Here's how we'll do this:&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;// index.js&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;puppyRouter&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;./routers/puppy&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="nx"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/puppies&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;puppyRouter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;these new lines of code can go directly beneath your Mongoose &lt;code&gt;connection&lt;/code&gt; function call&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;What the above is doing is telling our Express server that for any endpoint starting with &lt;code&gt;/puppies&lt;/code&gt; we want it to use the routing specified in our &lt;code&gt;puppy.js&lt;/code&gt; file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Now What?
&lt;/h2&gt;

&lt;p&gt;So we've told our Express server to use the &lt;code&gt;puppy&lt;/code&gt; router. Now what do we put in there to make this work?&lt;/p&gt;

&lt;p&gt;To start writing our routes, we first need to open up our &lt;code&gt;puppy.js&lt;/code&gt; file and add some requirements.&lt;/p&gt;

&lt;p&gt;First, in order to create our routes, we need to &lt;code&gt;require&lt;/code&gt; the Express &lt;code&gt;Router&lt;/code&gt;:&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;//puppy.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;router&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="nx"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This &lt;code&gt;router&lt;/code&gt; constant will be used to call all of our routing functions.&lt;/p&gt;

&lt;p&gt;Then we also need to require the &lt;code&gt;Puppy&lt;/code&gt; model we previously created, so that we can use our model to acces and make changes to data in our MongoDB 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="c1"&gt;//puppy.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;router&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="nx"&gt;Router&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;Puppy&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;../models/Puppy.model&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;Creating a route in Express is as easy as using the correct HTTP verb function (ie: &lt;code&gt;get&lt;/code&gt;, &lt;code&gt;post&lt;/code&gt;, etc) and pass in the route we want to use to preform that action.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;the rest of the code in this tutorial is going to be written inside of &lt;code&gt;puppy.js&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Reading from our MongoDB Collection
&lt;/h2&gt;

&lt;p&gt;We're going to start off easy and write a route to access &lt;em&gt;all&lt;/em&gt; of our puppies!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/qtw6YARlwUtvG/source.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/qtw6YARlwUtvG/source.gif" alt="a cute little row of 101 dalmations" width="369" height="281"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To do this, we're going to access our &lt;code&gt;Puppy&lt;/code&gt; model using some built-in Mongoose functions. Since our &lt;code&gt;const Puppy&lt;/code&gt; points to a Mongoose model, we don't also need to &lt;code&gt;require(mongoose)&lt;/code&gt; here, which I think is a nice perk!&lt;/p&gt;

&lt;p&gt;First, we need to set up an Express &lt;code&gt;get&lt;/code&gt; request:&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;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&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="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="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Gimme the puppies!&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;If you go ahead and start your server &lt;em&gt;(using the &lt;code&gt;dev&lt;/code&gt; script we added in a previous lesson)&lt;/em&gt; and navigate to &lt;code&gt;localhost:5000/puppies/&lt;/code&gt; you should see the string 'Gimme the puppies!'.&lt;/p&gt;

&lt;p&gt;What's happening here is we are telling Express we want to &lt;code&gt;get&lt;/code&gt; the &lt;code&gt;/&lt;/code&gt; route, and then we pass a callback that includes the &lt;code&gt;req&lt;/code&gt; (or request object), and the &lt;code&gt;res&lt;/code&gt; (or response). Then we're telling Express the &lt;code&gt;send&lt;/code&gt; the string "Gimme the puppies!" as our response.&lt;/p&gt;

&lt;p&gt;Pretty cool, right!?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now, let's get fancy&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We're going to add onto this route and use the built in Mongoose method &lt;code&gt;find&lt;/code&gt; to access every &lt;code&gt;Puppy&lt;/code&gt; in our collection.&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;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&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="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="nx"&gt;Puppy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;find&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;puppies&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;puppies&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Error: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;err&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;Above, we are using the the same &lt;code&gt;get&lt;/code&gt; request frame, and now we're using the Mongoose &lt;code&gt;find&lt;/code&gt; method to access all of the instances of &lt;code&gt;Puppy&lt;/code&gt; in our collection, and send them back to the response as JSON.&lt;/p&gt;

&lt;p&gt;Since &lt;code&gt;find&lt;/code&gt; is an &lt;strong&gt;asynchronous&lt;/strong&gt; function, we use &lt;code&gt;then&lt;/code&gt; to access and take action on the data that gets returned to us, only once the data has been returned. We also include a &lt;code&gt;catch&lt;/code&gt; just in case there's an error. In this case, if there's an error, we send back a &lt;code&gt;400&lt;/code&gt; status code to indicate a server error, and send back the error details as JSON. (&lt;em&gt;we will use this error format for every database request we write in this tutorial&lt;/em&gt;)&lt;/p&gt;

&lt;p&gt;Now if you were to look at this route in your browser, you'll see nothing returned. And that's a good thing! We haven't added a &lt;code&gt;Puppy&lt;/code&gt; to our collection yet, so there's nothing to be returned.&lt;/p&gt;

&lt;p&gt;Let's fix that...&lt;/p&gt;

&lt;h2&gt;
  
  
  Updating Our Collection
&lt;/h2&gt;

&lt;p&gt;Before we get started with sending our data to our database, we need a &lt;strong&gt;way&lt;/strong&gt; to do that. My preferred method is a product called &lt;a href="https://www.postman.com"&gt;Postman&lt;/a&gt;. Postman allows you to manually test API endpoints by creating request bodies manually without needing an actual GUI form or interactive element to send your data with.&lt;/p&gt;

&lt;p&gt;Go ahead and download Postman, and then come back for this next part, or if you have another API interaction tool you prefer feel free to use that!&lt;/p&gt;

&lt;p&gt;Now that we have Postman, and are able to test our endpoints, we can go ahead and set up our first &lt;code&gt;post&lt;/code&gt; route.&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;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;/&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="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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&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;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;breed&lt;/span&gt; &lt;span class="o"&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;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;breed&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Number&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;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&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;cute&lt;/span&gt; &lt;span class="o"&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;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cute&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;well_behaved&lt;/span&gt; &lt;span class="o"&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;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;well_behaved&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;adopted&lt;/span&gt; &lt;span class="o"&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;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;adopted&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newPuppy&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;Puppy&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="nx"&gt;breed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;cute&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;well_behaved&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;adopted&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;

  &lt;span class="nx"&gt;newPuppy&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;save&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&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;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;New puppy created!&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;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Error: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;err&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 one's pretty long, so let's step through this code and talk about what's happening.&lt;/p&gt;

&lt;p&gt;First, we set up our &lt;code&gt;post&lt;/code&gt; request route, and pass in the root route (&lt;code&gt;/&lt;/code&gt;). This will send the post request to &lt;code&gt;/puppies/&lt;/code&gt;, which is the RESTful endpoint for adding new instances to our collection.&lt;/p&gt;

&lt;p&gt;Then, we create some variables from the data passed in from our &lt;code&gt;req.body&lt;/code&gt;, or the body of our request. When we test this endpoint, we're going to be passing in a set of key-value pairs where the &lt;code&gt;key&lt;/code&gt; is the same as the data column we want to add to for this &lt;code&gt;Puppy&lt;/code&gt;. If you &lt;em&gt;know&lt;/em&gt; that your data will always been passed to the API in this format (via some sort of client-side validation, for example) you can alternatively pass the entire &lt;code&gt;req.body&lt;/code&gt; to &lt;code&gt;new Puppy()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We then take all of those variables and use them to create a &lt;code&gt;new&lt;/code&gt; instance of our &lt;code&gt;Puppy&lt;/code&gt; model. Once we have our instance of a &lt;code&gt;Puppy&lt;/code&gt;, we can use the built in Mongoose function &lt;code&gt;save&lt;/code&gt; to add this &lt;code&gt;Puppy&lt;/code&gt; to our MongoDB collection. Just like the &lt;code&gt;find&lt;/code&gt; method, the &lt;code&gt;save&lt;/code&gt; method is &lt;strong&gt;asynchronous&lt;/strong&gt;, so we will use &lt;code&gt;then&lt;/code&gt; to send back our response. The &lt;code&gt;save&lt;/code&gt; method does not return any data by default, so instead we'll just send back the string &lt;code&gt;"New puppy created!"&lt;/code&gt; to indicate success here.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now we can save our router file and test this out in Postman!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZI7aEATT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/9izwsbmujtoptmjaohwi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZI7aEATT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/9izwsbmujtoptmjaohwi.png" alt="Example of a post route in Postman using Puppy data" width="678" height="530"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the example above, you can see that I've chosen the &lt;code&gt;post&lt;/code&gt; verb option from the dropdown on the left-hand side, passed in our full URL (localhost:5000/puppies/) and then used the request body creator below to pass in my &lt;code&gt;Puppy&lt;/code&gt; data as raw JSON. (&lt;em&gt;Make sure to choose JSON from the dropdown!&lt;/em&gt;)&lt;/p&gt;

&lt;p&gt;Here's the puppy I created:&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="err"&gt;//req.body&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;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Hank"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"breed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"English Springer Spaniel"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"age"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"cute"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"well_behaved"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"adopted"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&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;/div&gt;



&lt;p&gt;Then we can click "Send" and the result panel at the bottom will read "New puppy created!"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/11qwfyd5mTJvDa/source.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/11qwfyd5mTJvDa/source.gif" alt="An English Springer Spaniel being scrutinized from some very similar looking cows" width="480" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now if we create a new tab using the &lt;code&gt;+&lt;/code&gt; symbol button at the top, we can create a &lt;code&gt;get&lt;/code&gt; request to &lt;code&gt;/puppies/&lt;/code&gt; and see our new &lt;code&gt;Puppy&lt;/code&gt; returned to us from the database!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xelJ_igr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/9vyhx5950czsbjvbk59e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xelJ_igr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/9vyhx5950czsbjvbk59e.png" alt="Get request for all puppy data" width="714" height="605"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we get back the puppy we created, and we can see that MongoDB automatically gave our instance of a &lt;code&gt;Puppy&lt;/code&gt; an &lt;code&gt;_id&lt;/code&gt; field populated with a unique ID code. We'll be using this &lt;code&gt;_id&lt;/code&gt; field to &lt;code&gt;get&lt;/code&gt; individual instances of a &lt;code&gt;Puppy&lt;/code&gt;, as well as making updates via &lt;code&gt;put&lt;/code&gt; request, and eventually, sadly, &lt;code&gt;delete&lt;/code&gt;-ing puppies if necessary.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reading Specific Data
&lt;/h2&gt;

&lt;p&gt;Now that we know how to add puppies to our collection, it's understandable that we won't &lt;em&gt;always&lt;/em&gt; want to get information about every single &lt;code&gt;Puppy&lt;/code&gt; in our collection. Personally, I'm most interested in Hank, because he's &lt;em&gt;my&lt;/em&gt; puppy. So how do I access only the data about him?&lt;/p&gt;

&lt;p&gt;We can use a method that's very similar to the &lt;code&gt;find&lt;/code&gt; method we used previously. Mongoose provides us with the method &lt;code&gt;findById&lt;/code&gt;, and it does exactly what it says on the tin. We simply pass in the &lt;code&gt;_id&lt;/code&gt; of the &lt;code&gt;Puppy&lt;/code&gt; we want to find.&lt;/p&gt;

&lt;p&gt;To get access to the &lt;code&gt;_id&lt;/code&gt; information, we're going to use a route &lt;code&gt;parameter&lt;/code&gt; by adding on to our base &lt;code&gt;/puppies/&lt;/code&gt; route. Here's the &lt;code&gt;get&lt;/code&gt; request we'll be using:&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;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/:id&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="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="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`The id you want to get is &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;params&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;`&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;Using the above, if you navigate to &lt;code&gt;localhost:5000/puppies/123&lt;/code&gt;, you should see the string "The id you want to get is 123" in your browser window.&lt;/p&gt;

&lt;p&gt;We'll be using &lt;code&gt;req.params.id&lt;/code&gt; to send a specific &lt;code&gt;_id&lt;/code&gt; to MongoDB in order to access the specific &lt;code&gt;Puppy&lt;/code&gt; we want.&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;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/:id&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="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="nx"&gt;Puppy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;findById&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;params&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="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;puppy&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;puppy&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Error: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;err&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;Now, we're using the aforementioned &lt;code&gt;findById&lt;/code&gt; method, coupled with the &lt;code&gt;id&lt;/code&gt; passed to us from &lt;code&gt;req.params.id&lt;/code&gt; to request only that instance of a &lt;code&gt;Puppy&lt;/code&gt;, and send the data back as JSON.&lt;/p&gt;

&lt;p&gt;We can test this in Postman, using the &lt;code&gt;_id&lt;/code&gt; that was assigned to the &lt;code&gt;Puppy&lt;/code&gt; we previously created...&lt;/p&gt;

&lt;p&gt;&lt;em&gt;your &lt;code&gt;_id&lt;/code&gt; will be different, as each &lt;code&gt;_id&lt;/code&gt; is completely unique&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--F4VZrfqx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/p061ew2ze99qnr0iz014.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--F4VZrfqx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/p061ew2ze99qnr0iz014.png" alt="Postman API call to our /puppies/:id route, using the ID from the previously created puppy" width="503" height="548"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you should see above, we make a &lt;code&gt;get&lt;/code&gt; request to &lt;code&gt;/puppies/:id&lt;/code&gt;, passing in the &lt;code&gt;_id&lt;/code&gt; for our previously created &lt;code&gt;Puppy&lt;/code&gt; in place of &lt;code&gt;:id&lt;/code&gt;, and we get back that instance of &lt;code&gt;Puppy&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you want to test this out further, I encourage you to create a few more &lt;code&gt;Puppy&lt;/code&gt; instances using our previously created &lt;code&gt;post&lt;/code&gt; route, and then access each of them one at a time using this new route.&lt;/p&gt;

&lt;h2&gt;
  
  
  Updating Instances
&lt;/h2&gt;

&lt;p&gt;Now that we're able to get data to and from our database, we also want to be able to make changes. In the event that a &lt;code&gt;Puppy&lt;/code&gt; ages, gets adopted, or gets some training and becomes well behaved, we want to be able to update those details in our database.&lt;/p&gt;

&lt;p&gt;This process is an amalgamation of what we've done so far. It's similar to &lt;code&gt;get&lt;/code&gt;-ting and &lt;code&gt;post&lt;/code&gt;-ing an individual instance of a &lt;code&gt;Puppy&lt;/code&gt;. Remember how Mongoose gave us a convenient &lt;code&gt;findById&lt;/code&gt; method? Mongoose also gives us a &lt;code&gt;findOneAndUpdate&lt;/code&gt; method for finding and updating instances.&lt;/p&gt;

&lt;p&gt;However, in order to use this function, we need to make an update to our &lt;code&gt;mongoose.connect&lt;/code&gt; function in our &lt;code&gt;index.js&lt;/code&gt; file.&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;// index.js&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="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;useNewUrlParser&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;useUnifiedTopology&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;useFindAndModify&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="c1"&gt;// this is the new line of code we're adding&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code block, passing another option to our &lt;code&gt;connect&lt;/code&gt; function and telling Mongoose to set &lt;code&gt;useFindAndModify&lt;/code&gt; to false. This will allow us to use the Mongoose &lt;code&gt;findOneAndUpdate&lt;/code&gt; method. It's not important in this use case to understand why we're doing this, but if you want to learn more about this, you can check out the &lt;a href="https://mongoosejs.com/docs/deprecations.html"&gt;Mongoose documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now that we've got that sorted out, we can create our &lt;code&gt;update&lt;/code&gt; route using the &lt;code&gt;put&lt;/code&gt; http verb...&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;router&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/:id/update&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="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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;updates&lt;/span&gt; &lt;span class="o"&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;body&lt;/span&gt; &lt;span class="c1"&gt;//we set a variable equal to the entire req.body&lt;/span&gt;

  &lt;span class="nx"&gt;Puppy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;findOneAndUpdate&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;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&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;updates&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;new&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="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;updatedPuppy&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;updatedPuppy&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Error: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;err&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;In this scenario, we are assuming that the only data being passed in the &lt;code&gt;req.body&lt;/code&gt; are the updates being made to this specific puppy. Otherwise, we would need to write some extra code to extract the specific updates being made.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;findOneAndUpdate&lt;/code&gt; conveniently indentifies whether the instance being accessed already has the &lt;code&gt;key&lt;/code&gt; (or multiple keys) being passed in by the update object. And since we created this model using a schema, we are only allowed to update columns that already exist. If we were to try to send an update that included a column that does not exist, no updates will be made to the database.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;findOneAndUpdate&lt;/code&gt; takes in 2 required arguments, and one optional:&lt;br&gt;
First we find the &lt;code&gt;Puppy&lt;/code&gt; we're targeting by looking for a &lt;code&gt;Puppy&lt;/code&gt; instance with a matching &lt;code&gt;_id&lt;/code&gt; (&lt;code&gt;{ _id: req.params.id }&lt;/code&gt;), then we pass in the &lt;code&gt;updates&lt;/code&gt; variable as the second argument. We can also include &lt;code&gt;{ new: true }&lt;/code&gt; as an optional third argument, which will cause the updated &lt;code&gt;Puppy&lt;/code&gt; data to be returned from the function.&lt;/p&gt;

&lt;p&gt;We can test this new endpoint, again using Postman. Let's say I got my &lt;code&gt;Puppy&lt;/code&gt; Hank some training lessons, and he's now perfectly well behaved. I can send an update to this endpoint, and in the request body test &lt;code&gt;well_behaved&lt;/code&gt; to &lt;code&gt;true&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--spaaIXe6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/277aay4pq0kc8r6naksf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--spaaIXe6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/277aay4pq0kc8r6naksf.png" alt="Updating a puppy using our /:id/update endpoint" width="634" height="642"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You should see above that I sent the request to this new endpoint that I described above, and in the reponse we see the updated &lt;code&gt;Puppy&lt;/code&gt; instance for Hank, where &lt;code&gt;well_behaved&lt;/code&gt; is now set to &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Deleting Data
&lt;/h2&gt;

&lt;p&gt;Sadly, the only thing left to do is to delete some of our puppies.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://i.giphy.com/media/MAtKCGwJHblVC/source.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/MAtKCGwJHblVC/source.gif" alt="a puppy who is very sad that they are about to be deleted" width="640" height="360"&gt;&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Since you've been following along, I bet you can guess what http verb we need to use this time: &lt;code&gt;delete&lt;/code&gt;!&lt;/p&gt;

&lt;p&gt;Similarly to the built in &lt;code&gt;findOneAndUpdate&lt;/code&gt; method, Mongoose also provides us with a convenient &lt;code&gt;findByIdAndDelete&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;Here's how we'll utilize this method in our API:&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;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/:id&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="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="nx"&gt;Puppy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;findByIdAndDelete&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;params&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="nx"&gt;then&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;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Puppy deleted =( &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;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Error: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;err&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 works pretty similarly to our &lt;code&gt;findById&lt;/code&gt; method. We pass in the &lt;code&gt;_id&lt;/code&gt; of our &lt;code&gt;Puppy&lt;/code&gt; as a request &lt;code&gt;param&lt;/code&gt;, and the method does the rest of the work for us. As with all of our other Mongoose methods, this is &lt;strong&gt;asynchronous&lt;/strong&gt;, and like the &lt;code&gt;save&lt;/code&gt; method does not return any data to us. Instead we send back the string &lt;code&gt;"Puppy deleted =("&lt;/code&gt; to indicate successful deletion.&lt;/p&gt;

&lt;p&gt;Test this route at your own peril, because deleting puppies is pretty sad!&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;Congrats! You made it through every single CRUD action with Express and Mongoose! Now it's time to celebrate 🎉&lt;/p&gt;

&lt;p&gt;If you made it this far I just want to say: &lt;strong&gt;Thank you and I'm so proud of you!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I encourage you to use what you've learned here to build your own REST API with Express and Mongoose to practice what you've learned.&lt;/p&gt;

&lt;p&gt;If you do follow this tutorial and build an API of your own I'd love to see it! Share what you've made with &lt;a href="https://twitter.com/thecodepixi"&gt;on Twitter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to find out when I put out new blog posts and tutorials, you can &lt;a href="https://twitter.com/thecodepixi"&gt;follow me on Twitter&lt;/a&gt;, where I always post links as soon as my new posts are available.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This tutorial was originally posted on &lt;a href="https://thecodepixi.dev/blog"&gt;TheCodePixi.dev/blog&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>node</category>
      <category>mongodb</category>
      <category>tutorial</category>
      <category>database</category>
    </item>
    <item>
      <title>Enamel Pins for Developers</title>
      <dc:creator>Emmy | Pixi</dc:creator>
      <pubDate>Fri, 12 Jun 2020 01:47:03 +0000</pubDate>
      <link>https://dev.to/thecodepixi/enamel-pins-for-developers-53gl</link>
      <guid>https://dev.to/thecodepixi/enamel-pins-for-developers-53gl</guid>
      <description>&lt;p&gt;We all know developers (myself included) &lt;strong&gt;love&lt;/strong&gt; their stickers! &lt;/p&gt;

&lt;p&gt;We cover our laptops in them, stick them on our cars, our notebooks, everywhere sticky things will...ya know...stick. &lt;/p&gt;

&lt;p&gt;But what about sticking things...&lt;strong&gt;on ourselves&lt;/strong&gt;!? &lt;/p&gt;

&lt;p&gt;I have always been a &lt;em&gt;huge&lt;/em&gt; fan of enamel pins, and have amassed a decent collection of them over the years. &lt;/p&gt;

&lt;p&gt;Despite the absolute wealth of development, programming, and coding related stickers there are in the world, I had a genuinely difficult (almost impossible) time finding any enamel pins that fit the theme. &lt;/p&gt;

&lt;p&gt;So, I decided to make my own! 🎉 &lt;/p&gt;

&lt;p&gt;My first two pin designs are available for pre-order &lt;a href="https://shop.thecodepixi.dev"&gt;on my website&lt;/a&gt;, and I'm looking forward to designing many many more in the future. &lt;/p&gt;

&lt;p&gt;If you're also a pin collector, or have any cool coding-related pin ideas, let me know in the comments! &lt;/p&gt;

&lt;p&gt;xx - Emily / Pixi &lt;/p&gt;

</description>
      <category>watercooler</category>
      <category>design</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Setting Up An Express API with Mongoose</title>
      <dc:creator>Emmy | Pixi</dc:creator>
      <pubDate>Thu, 11 Jun 2020 15:01:03 +0000</pubDate>
      <link>https://dev.to/thecodepixi/setting-up-an-express-api-with-mongoose-2073</link>
      <guid>https://dev.to/thecodepixi/setting-up-an-express-api-with-mongoose-2073</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This is a continuation of a series on Express. If you have never used Express before I recommend &lt;a href="https://thecodepixi.dev/blog/your-first-express-server"&gt;starting here&lt;/a&gt; instead.&lt;/p&gt;

&lt;p&gt;This is Part 1 of a 2 part tutorial. Part 2 coming soon...&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;If you prefer to jump straight into the code, you can find the repo for this tutorial &lt;a href="https://github.com/thecodepixi/express-mongoose-api-tutorial-part1"&gt;here&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's get started...
&lt;/h2&gt;

&lt;p&gt;To get started with writing a REST API with Express, we first need to set up our project folder.&lt;/p&gt;

&lt;p&gt;Let's open up a terminal and &lt;code&gt;cd&lt;/code&gt; into where ever we want to work on our coding projects. For me, that's &lt;code&gt;cd code&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Then we want to create a new folder for our project to live in, and initialize our &lt;code&gt;package.json&lt;/code&gt;:&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="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;express-rest-api
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;express-rest-api
&lt;span class="nv"&gt;$ &lt;/span&gt;yarn init &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;I'm choosing to use &lt;code&gt;yarn&lt;/code&gt; as my package manager, but you can use &lt;code&gt;npm&lt;/code&gt; if you prefer. Both will work the same for this project&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now we need to add all of the dependencies for our project. There are quite a few, so let's go over them quickly, one by one:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;express&lt;/code&gt; : Express is a &lt;a href="//expressjs.com"&gt;minimal and flexible Node.js web application framework&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;nodemon&lt;/code&gt; : &lt;a href="https://nodemon.io/"&gt;Nodemon&lt;/a&gt; is a utility that automatically restarts your server on save to provide "hot reloading" and increased efficiency (&lt;em&gt;this will be installed as a &lt;code&gt;devDepenency&lt;/code&gt;&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;dotenv&lt;/code&gt; : Dotenv allows us to store private/secret information (like our MongoDB URI) in a &lt;code&gt;.env&lt;/code&gt; file and access that information using a variable instead of plain text inside our code.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;cors&lt;/code&gt;: CORS stands for 'Cross Origin Resource Sharing'. We'll get into what that means a little later on when we start sending things like POST requests.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;mongoose&lt;/code&gt;: Mongoose is the MongoDB framework that we'll be using to create our database &lt;code&gt;Schema&lt;/code&gt; and access our database models. (&lt;em&gt;you can build this without Mongoose and just use MongoDB but I personally really enjoy Mongoose and find it to be a useful tool&lt;/em&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can add most of these packages in a single command from our terminal:&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="nv"&gt;$ &lt;/span&gt;yarn add express cors mongoose dotenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we can add &lt;code&gt;nodemon&lt;/code&gt; to our &lt;code&gt;devDependencies&lt;/code&gt; by adding the &lt;code&gt;-D&lt;/code&gt; flag:&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="nv"&gt;$ &lt;/span&gt;yarn add &lt;span class="nt"&gt;-D&lt;/span&gt; nodemon
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Basic Express Server Setup
&lt;/h2&gt;

&lt;p&gt;The "entry point" for this project is &lt;code&gt;index.js&lt;/code&gt; so we can create that using &lt;code&gt;touch index.js&lt;/code&gt; and then open that file in our favorite code editor (I'm using VS Code).&lt;/p&gt;

&lt;p&gt;The first thing we want to do is set up our basic Express server. Most of this process is covered in the &lt;a href="https://thecodepixi.dev/blog/your-first-express-server"&gt;first part of this series&lt;/a&gt;, so I won't go into too much detail on this here...&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;// index.js&lt;/span&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;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="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="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="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;5000&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="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="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="s2"&gt;`Server running on 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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// add this scripts object to your package.json &lt;/span&gt;
&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;scripts&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dev&lt;/span&gt;&lt;span class="dl"&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;nodemon index&lt;/span&gt;&lt;span class="dl"&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;run&lt;/span&gt;&lt;span class="dl"&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;node index&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;Now you can run &lt;code&gt;yarn run dev&lt;/code&gt; (&lt;em&gt;or &lt;code&gt;npm run dev&lt;/code&gt;&lt;/em&gt;) from the terminal and you should see your console log &lt;code&gt;"Server running on port 5000"&lt;/code&gt;. If you change the string inside the &lt;code&gt;console.log&lt;/code&gt;, since we are using nodemon, when you save the file you should see the terminal register that the server has restarted, and you should see your updated output logged in the terminal.&lt;/p&gt;

&lt;p&gt;🎉 Now we can start building our API!&lt;/p&gt;

&lt;p&gt;Since "To Do" apps are &lt;em&gt;&lt;strong&gt;so&lt;/strong&gt;&lt;/em&gt; 2018, we're going to be building an API to store and receive data about puppies. 🐶&lt;/p&gt;

&lt;h2&gt;
  
  
  MongoDB Setup
&lt;/h2&gt;

&lt;p&gt;First, since we're going to be using MongoDB as our database, coupled with the Mongoose framework, there's some setup that needs to be done to get a MongoDB Atlas account set up.&lt;/p&gt;

&lt;p&gt;MongoDB has a great tutorial on that &lt;a href="https://docs.atlas.mongodb.com/getting-started/"&gt;here&lt;/a&gt; that you should follow. When you have your MongoDB Atlas setup, come back here when you get to &lt;strong&gt;Step 5&lt;/strong&gt; of their tutorial and we'll move on to the next step together...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/oT7ATDykMidsk/source.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/oT7ATDykMidsk/source.gif" alt="Well, We're Waiting!" width="520" height="298"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Oh, Great! You're Back!
&lt;/h2&gt;

&lt;p&gt;So now you should have your MongoDB Atlas URI available. The string should look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mongodb+srv://&amp;lt;username&amp;gt;:&amp;lt;password&amp;gt;@clustername.mongodb.net/&amp;lt;dbName&amp;gt;?retryWrites=true&amp;amp;w=majority&amp;amp;useNewUrlParser=true&amp;amp;useUnifiedTopology=true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We're going to add an &lt;code&gt;.env&lt;/code&gt; file to our project, and store this string (replacing &lt;code&gt;username&lt;/code&gt;, &lt;code&gt;password&lt;/code&gt; with your cluster admin info).&lt;/p&gt;

&lt;p&gt;First we'll &lt;code&gt;touch .env&lt;/code&gt; inside of our project directory, and then we'll add the following to that file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  ATLAS_URI=mongodb+srv://yourUsername:yourPassword@clustername.mongodb.net/puppies?retryWrites=true&amp;amp;w=majority&amp;amp;useNewUrlParser=true&amp;amp;useUnifiedTopology=true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see we replaced &lt;code&gt;&amp;lt;username&amp;gt;&lt;/code&gt; with &lt;code&gt;yourUsername&lt;/code&gt; (your Atlas admin username), and &lt;code&gt;&amp;lt;password&amp;gt;&lt;/code&gt; with &lt;code&gt;yourPassword&lt;/code&gt; (your Atlas admin password).&lt;/p&gt;

&lt;p&gt;We also replaced &lt;code&gt;&amp;lt;dbName&amp;gt;&lt;/code&gt; with &lt;code&gt;puppies&lt;/code&gt;, which is what our database will be called when it gets added to our MongoDB Atlas Cluster.&lt;/p&gt;

&lt;p&gt;Now we want to add this info to &lt;code&gt;index.js&lt;/code&gt; so our app can connect to MongoDB via Mongoose:&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;//add require statements for mongoose, cors, and body-parser (for parsing json)&lt;/span&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;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;bodyParser&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;body-parser&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;//require dotenv to access variables inside .env&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;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;span class="c1"&gt;//tell our express app to use cors and bodyParser&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;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;bodyParser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

&lt;span class="c1"&gt;//connect our app to MongoDB with Mongoose&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="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;ATLAS_URI&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="c1"&gt;//open our MongoDB connection&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="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="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;MongoDB connection established&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;Now, if you're still running your server you should see &lt;code&gt;"MongoDB connection established"&lt;/code&gt; output to your console! If you're &lt;em&gt;not&lt;/em&gt; still running your server, start it using the &lt;code&gt;dev&lt;/code&gt; script we created earlier, and you should see both the &lt;code&gt;Server running&lt;/code&gt; and the &lt;code&gt;MongoDB connection&lt;/code&gt; logs in your terminal&lt;/p&gt;

&lt;p&gt;&lt;em&gt;**If you run into any errors with your MongoDB connection you may need to add a second argument to your &lt;code&gt;mongoose.connect()&lt;/code&gt; function with the follow:&lt;/em&gt;&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="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"useNewUrlParser"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"useUnifiedTopology"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"useCreateIndex"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&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;/div&gt;



&lt;p&gt;&lt;em&gt;However, since these options are specified in the our &lt;code&gt;ATLAS_URI&lt;/code&gt;, we hopefully shouldn't run into any errors.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating our Model and Schema
&lt;/h2&gt;

&lt;p&gt;Since we're building a relatively simple API, we're just going to have one model and one schema. We're going to put this model in a folder called &lt;code&gt;Models&lt;/code&gt;&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="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;models
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;models/Puppy.model.js

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To create our Schema we need to &lt;code&gt;require('mongoose')&lt;/code&gt; and create a Schema variable:&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;//Puppy.model.js&lt;/span&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;Schema&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;Schema&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;puppySchema&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Puppy&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;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;Puppy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;puppySchema&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;Puppy&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://i.giphy.com/media/gcXcSRYZ9cGWY/source.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/gcXcSRYZ9cGWY/source.gif" alt="A Basket Full O' Puppies" width="720" height="720"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We're going to put the definitions for all of the keys of our &lt;code&gt;Puppy&lt;/code&gt; model in the &lt;code&gt;new Schema({})&lt;/code&gt; assigned to &lt;code&gt;puppySchema&lt;/code&gt;. MongoDB offers all of the standard data types, and Mongoose provides validations for these types. We'll be exploring a few different data types and validations with this model.&lt;/p&gt;

&lt;p&gt;We want all of our &lt;code&gt;Puppies&lt;/code&gt; to have a &lt;code&gt;name&lt;/code&gt;, &lt;code&gt;age&lt;/code&gt;, and &lt;code&gt;breed&lt;/code&gt;, and we're also going to give them each &lt;code&gt;Boolean&lt;/code&gt; values of &lt;code&gt;cute&lt;/code&gt;,&lt;code&gt;well-behaved&lt;/code&gt;, and &lt;code&gt;adopted&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let's add these to our &lt;code&gt;Schema&lt;/code&gt; (&lt;em&gt;I've included code comments to explain the validations and typing along the way&lt;/em&gt;):&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;//Puppy.model.js&lt;/span&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;Schema&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;Schema&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;puppySchema&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="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//we want each name to be a string&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="c1"&gt;//puppies have to have names!&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="c1"&gt;//this will remove trailing whitespace from the string&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="c1"&gt;//each puppy name must be at least 3 characters long&lt;/span&gt;
    &lt;span class="na"&gt;minLength&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;breed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//breed has the same requirements as name&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;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;minLength&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//we'll be using ages in months&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;Number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="c1"&gt;//even puppies can't be ageless&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="c1"&gt;//puppies can't have negative ages&lt;/span&gt;
    &lt;span class="na"&gt;min&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="c1"&gt;//once they get about 12 months, they're not puppies anymore!&lt;/span&gt;
    &lt;span class="na"&gt;max&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;cute&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// you're either cute or you're not&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;Boolean&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;well_behaved&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;Boolean&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;adopted&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;Boolean&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Puppy&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;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;Puppy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;puppySchema&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;Puppy&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🎉🎉🎉 We did it! We've got our basic Express server hooked up to our own MongoDB cluster, and we've created our first Model Schema using Mongoose.&lt;/p&gt;

&lt;p&gt;It's time to take a well deserved break, get up, drink some water, and stretch out those typing fingers.&lt;/p&gt;

&lt;p&gt;Next week we'll be going through the process to set up all of our API endpoints, using Mongoose to access information from our database, and accomplish all of the CRUD actions through our API.&lt;/p&gt;

&lt;p&gt;If you want to find out when I put out new blog posts and tutorials, you can &lt;a href="https://twitter.com/thecodepixi"&gt;follow me on Twitter&lt;/a&gt;, where I always post links as soon as my new posts are available.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This article was originally posted to &lt;a href="https://thecodepixi.dev/blog"&gt;TheCodePixi.dev/blog&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>javascript</category>
      <category>mongodb</category>
      <category>node</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Job Search Self Care and Anxiety Management</title>
      <dc:creator>Emmy | Pixi</dc:creator>
      <pubDate>Sat, 06 Jun 2020 18:50:57 +0000</pubDate>
      <link>https://dev.to/thecodepixi/job-search-self-care-and-anxiety-management-4je0</link>
      <guid>https://dev.to/thecodepixi/job-search-self-care-and-anxiety-management-4je0</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;We all know the job search can be stressful, and sometimes even traumatic. So, what can we do to make sure we are supporting our mental health while looking for work?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As someone with a triple threat of mental health conditions &lt;em&gt;[GAD, CPTSD, ADHD]&lt;/em&gt;, I know better than most how hard it can be to manage your mental health while looking for work. On top of the typical stress that comes with the job search process, many of us are now looking for work during a global health crisis, a civil rights movement, and a financial depression. All of those factors bundled together can lead to a fire-storm of anxiety-inducing scenarios, that coupled with the inherent anxiety and stress of a typical job search, can make the task seems insurmountable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Firstly, I am here to tell you a few things about yourself:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;You are strong&lt;/li&gt;
&lt;li&gt;You are capable&lt;/li&gt;
&lt;li&gt;You are worthy&lt;/li&gt;
&lt;li&gt;You are skilled&lt;/li&gt;
&lt;li&gt;You are enough&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Now that we've gotten that out of the way ...
&lt;/h3&gt;

&lt;p&gt;Many &lt;em&gt;(if not most)&lt;/em&gt; of the people reading this will have experienced stress, anxiety, or even trauma, at some point in their lives. Unfortunately, most of us have not been prepared for how to mentally and emotionally handle these experiences.&lt;/p&gt;

&lt;p&gt;One of the best anxiety coping mechanisms I have ever learned is focusing on your &lt;strong&gt;locus of control&lt;/strong&gt;.&lt;br&gt;
Many times, the things that cause us the &lt;em&gt;most&lt;/em&gt; anxiety, are the things over which we have &lt;em&gt;no control&lt;/em&gt;. Once we are able to mentally and emotionally relinquish the desire to control the uncontrollable, and the anxiety over having no control over those things, we can productively focus on the things we &lt;em&gt;can&lt;/em&gt; control.&lt;/p&gt;

&lt;h3&gt;
  
  
  What can you control in your job search?
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Under Your Control&lt;/th&gt;
&lt;th&gt;Not Under Your Control&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;The quality of your resume&lt;/td&gt;
&lt;td&gt;Automatic rejections based on an algorithm&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Your preparedness for an interview&lt;/td&gt;
&lt;td&gt;The behavior of your interview and content of their questions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The quantity and quality of your projects&lt;/td&gt;
&lt;td&gt;A lack of open positions for someone with your skillset&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Your attitude and outlook&lt;/td&gt;
&lt;td&gt;The opinions of others&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;This list will vary from person to person.&lt;/strong&gt; I highly encourage you to make a list like this that suits your own scenario.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Not sure where to start?&lt;/strong&gt; Make a list of what's causing you anxiety in your job search, then divide those things among the "Can Control" and "Can't Control" columns.&lt;br&gt;
Do your best to let go of a desire to control what you cannot. Recognizing that it's out of your control can go a &lt;em&gt;long way&lt;/em&gt; to easing some of your anxiety around those things.&lt;/p&gt;

&lt;h3&gt;
  
  
  But what if the lack of control is what causes your anxiety?
&lt;/h3&gt;

&lt;p&gt;Unfortunately, this one is going to require significantly more inner work.&lt;br&gt;
There is no quick-fix to being a &lt;em&gt;"control freak"&lt;/em&gt;. This is something I have struggled with, and continue to struggle with, on a nearly daily basis.&lt;/p&gt;

&lt;p&gt;The best advice I can give you is to first start by recognizing when you are grasping for control. Recognizing those behaviors and reactions within yourself is your first step to redirecting and correcting those thoughts and behaviors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Once you've recognized your own patterns, you can then redirect and correct.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Refocus to things you &lt;em&gt;can&lt;/em&gt; control. Go back to the list you made of what things are actually under your control, and focus on those instead.&lt;/p&gt;

&lt;p&gt;Utilize meditation practices, and repeat a mantra to yourself. It's important to find a mantra that works for you personally, but something like &lt;em&gt;"I control what I can and release what I can't"&lt;/em&gt; could be a good place to start.&lt;/p&gt;

&lt;h3&gt;
  
  
  Finally, make time for non-job-search related activities that fill you up
&lt;/h3&gt;

&lt;p&gt;This can be &lt;em&gt;&lt;strong&gt;ANYTHING&lt;/strong&gt;&lt;/em&gt;. Any hobby you have that is not directly related to your job search can work here.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Read a good book, work on a craft project, work on a coding project that's &lt;strong&gt;just for fun&lt;/strong&gt;, play a video game you love, play a board game with friends, indulge in your skincare routine, bake your favorite pastry, cook your favorite meal.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;The options are endless.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Remind yourself that you are allowed to take time away from the pressures of your job search. It will still be there when you go back to it.&lt;/p&gt;

&lt;p&gt;Time away from a task is &lt;em&gt;essential&lt;/em&gt; to allowing your brain to relax, and your mind to de-stress. Focusing on something that's just for you, and just for fun, &lt;em&gt;is so important&lt;/em&gt; to your mental and emotional wellbeing.&lt;/p&gt;

&lt;h3&gt;
  
  
  But what if I still can't get a handle on my anxiety?
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;If your anxiety is truly overwhelming and pervasive, it is &lt;em&gt;extremely important&lt;/em&gt; that you seek professional help.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Talking to a therapist or other mental health professional can be the difference between suffering and relief for so many people. If you have the financial privilege and means to seek professional help, I &lt;em&gt;highly encourage&lt;/em&gt; you to do so. They will be the best person to give you concrete tools and guidance for approaching your personal situation, and will be there to advise you on whether looking to medication for relief might be the right choice for you.&lt;/p&gt;

&lt;p&gt;Personally, I have found &lt;em&gt;great relief&lt;/em&gt; through a combination of supplementing with &lt;a href="https://dailydosecbdinc.com"&gt;Full-Spectrum CBD&lt;/a&gt; and &lt;a href="https://www.mdlinx.com/article/one-supplement-you-should-start-taking-now/lfc-3252"&gt;L-Theanine&lt;/a&gt;. I take a 20mg dose of sublingual CBD, and 100mg capsule of L-Theanine twice per day, and it has done wonders for my stress response, anxiety levels, and overall mood.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I am not a healthcare professional&lt;/strong&gt; and cannot advise you on what you should or should not do for yourself, in terms of botanical supplements*. However, I do recommend reaching out to someone with the authority to do so (&lt;em&gt;your own doctor, for example&lt;/em&gt;), to see if this could be a good option for you.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;* If you are generally in good health, both of these supplements are free from&lt;br&gt;
  side-effects and safe to try, if you choose to do so without first consulting&lt;br&gt;
  your healthcare provider.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In closing, I just want to say: I see you.&lt;br&gt;
You are working so hard, and will get there soon. We both will. I believe in us. 💕&lt;/p&gt;

&lt;p&gt;&lt;em&gt;this article was originally posted on &lt;a href="https://thecodepixi.dev/blog/"&gt;TheCodePixi.dev/blog/&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>mentalhealth</category>
      <category>career</category>
    </item>
    <item>
      <title>A Ruby on Rails Roadmap</title>
      <dc:creator>Emmy | Pixi</dc:creator>
      <pubDate>Wed, 27 May 2020 22:08:25 +0000</pubDate>
      <link>https://dev.to/thecodepixi/a-ruby-on-rails-roadmap-34i4</link>
      <guid>https://dev.to/thecodepixi/a-ruby-on-rails-roadmap-34i4</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Are you a beginner or newbie looking to get started with Ruby on Rails?&lt;/strong&gt; I've compiled some &lt;strong&gt;FREE&lt;/strong&gt; resources to help you get started in just &lt;strong&gt;under 6 hours&lt;/strong&gt;...&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I had the opportunity to learn Ruby and Ruby on Rails during my time at Flatiron School and almost immediately &lt;strong&gt;fell in love&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Ruby is an extremely accessible language and, in my opinion, a really ideal first programming language. It's a dynamically typed, expressive language that lends itself to being human readable and just a joy to work with. &lt;/p&gt;

&lt;p&gt;Recently (as in, today) a &lt;a href="//www.twitter.com/amdev83"&gt;friend&lt;/a&gt; popped into the &lt;a href="//www.twitter.com/codecafeonline"&gt;Code Cafe Online&lt;/a&gt; Discord and asked for advice on learning Ruby on Rails. As a result, I ended up putting together this beginner Ruby on Rails Roadmap of free video courses! &lt;/p&gt;

&lt;p&gt;If you're a beginner looking to learn Ruby on Rails, or a developer with experience in other languages looking to add Ruby or Ruby on Rails to your skill set, this should help you get started...&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Ruby Crash Course
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Time Commitment:&lt;/strong&gt; 4 Hours&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/t_ispmWmdjY"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Ruby on Rails Crash Course
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Time Commitment:&lt;/strong&gt; 1 Hour&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/pPy0GQJLZUM"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Ruby on Rails REST API Tutorial
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Time Commitment:&lt;/strong&gt; &amp;lt; 1 Hour&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/QojnRc7SS9o"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In just under 6 hours, you've gone from a total Ruby newbie, to a Ruby on Rails wiz kid! 🎉&lt;/p&gt;

&lt;p&gt;I hope this little learning roadmap is useful to all the future Rubyists out there! If you ever need help or get stuck on your learning journey, you can find me on &lt;a href="//www.twitter.com/thecodepixi"&gt;Twitter&lt;/a&gt; and here on DEV. I'm always happy to help debugging some Ruby code!  &lt;/p&gt;

&lt;p&gt;xx - Emily/TheCodePixi&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>codenewbie</category>
      <category>beginners</category>
    </item>
    <item>
      <title>New MacBook Pro Dev Setup</title>
      <dc:creator>Emmy | Pixi</dc:creator>
      <pubDate>Sat, 23 May 2020 00:00:14 +0000</pubDate>
      <link>https://dev.to/thecodepixi/new-macbook-pro-dev-setup-34ec</link>
      <guid>https://dev.to/thecodepixi/new-macbook-pro-dev-setup-34ec</guid>
      <description>&lt;p&gt;A quick run down of everything I did to get my dev environment up and running on my new 2020 MacBook Pro...&lt;/p&gt;

&lt;h2&gt;
  
  
  First Things First...
&lt;/h2&gt;

&lt;p&gt;Before I did anything with my new laptop, I first made sure to backup anything I wanted to save from my old laptop (a late 2014 MacBook Air). This included making a copy of the &lt;code&gt;settings.json&lt;/code&gt; in VSCode, checking for and special settings in the &lt;code&gt;.bashrc&lt;/code&gt; and &lt;code&gt;.zshrc&lt;/code&gt; files, and backing up all of my documents. &lt;/p&gt;

&lt;h2&gt;
  
  
  Next Things Next...
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;first&lt;/strong&gt; thing I do with any new computer is go through the setup process and then check for software updates. Then I download any software that I know I'll need. &lt;/p&gt;

&lt;h3&gt;
  
  
  For this setup this included:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;VSCode &lt;/li&gt;
&lt;li&gt;Firefox&lt;/li&gt;
&lt;li&gt;Chrome&lt;/li&gt;
&lt;li&gt;Affinity Designer&lt;/li&gt;
&lt;li&gt;Postgres&lt;/li&gt;
&lt;li&gt;Discord&lt;/li&gt;
&lt;li&gt;Slack&lt;/li&gt;
&lt;li&gt;Zoom&lt;/li&gt;
&lt;li&gt;Streamlabs OBS&lt;/li&gt;
&lt;li&gt;Spotify &lt;/li&gt;
&lt;li&gt;iTerm2 (with OhMyZsh) &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then I went into iTerm2 and setup a new custom profile, as well as making customizations to my OhMyZsh settings. &lt;/p&gt;

&lt;p&gt;After I had my terminal setup, I went into VSCode and replaced the contents of the &lt;code&gt;settings.json&lt;/code&gt; with the saved copy from my old laptop. &lt;/p&gt;

&lt;h2&gt;
  
  
  Last Things Last.
&lt;/h2&gt;

&lt;p&gt;The last thing I do to make sure I have everything I need is to go through and make sure I install all of the CLI programs I'll need for my development process. With this computer that meant updating XCode, updating Node and Ruby, and then installing Homebrew, NPM, React, Gatsby, and Rails. &lt;/p&gt;

&lt;p&gt;I also made sure that when I was backing up my previous laptop, I made a list of all of the extensions I had in my previous install of VSCode. Re-installing those on my new machine is the last step of the process. &lt;/p&gt;

&lt;h3&gt;
  
  
  My Favorite VSCode Extensions:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Dracula Official (theme)&lt;/li&gt;
&lt;li&gt;Panda (theme)&lt;/li&gt;
&lt;li&gt;Prettier&lt;/li&gt;
&lt;li&gt;ESLint&lt;/li&gt;
&lt;li&gt;Bracket Pair Colorizer &lt;/li&gt;
&lt;li&gt;Code Spell Checker&lt;/li&gt;
&lt;li&gt;Live Server&lt;/li&gt;
&lt;li&gt;JS JSX Snippets&lt;/li&gt;
&lt;li&gt;Material Icon Theme&lt;/li&gt;
&lt;li&gt;Ruby / VSCode Ruby&lt;/li&gt;
&lt;li&gt;WakaTime &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let me know how similar or different this is from your process of setting up a new machine! This is the basic "must have" list and doesn't include the fun stuff like choosing a new wallpaper or making sure I have &lt;a href="//www.fliqlo.com"&gt;my favorite screensaver&lt;/a&gt; installed. &lt;/p&gt;

&lt;p&gt;xx Pixi / Emily &lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>computerscience</category>
      <category>macbook</category>
    </item>
    <item>
      <title>Hello World! { Setting Up Your First Express Server }</title>
      <dc:creator>Emmy | Pixi</dc:creator>
      <pubDate>Mon, 11 May 2020 16:36:03 +0000</pubDate>
      <link>https://dev.to/thecodepixi/hello-world-setting-up-your-first-express-server-2f98</link>
      <guid>https://dev.to/thecodepixi/hello-world-setting-up-your-first-express-server-2f98</guid>
      <description>&lt;h3&gt;
  
  
  But what is Express anyway?
&lt;/h3&gt;

&lt;p&gt;Express is a &lt;a href="//expressjs.com"&gt;minimal and flexible Node.js web application framework&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Express is a great backend and API option for any project with a JavaScript (or JS framework) frontend, because it allows you to keep all of your code in the same language and the same family. You don't need to learn one language for the front end and an entirely different language for the back. If you already work in JavaScript for your frontend projects, I think you'll be able to pick up Express really quickly. I know I did! &lt;/p&gt;

&lt;h3&gt;
  
  
  Sweet! Let's get started!
&lt;/h3&gt;

&lt;p&gt;Before getting started with Express, it's important to make sure that you have Node installed on your system, and that you have at least some exposure to Node. &lt;/p&gt;

&lt;p&gt;I highly recommend &lt;a href="%5Bhttps://youtu.be/fBNz5xF-Kx4%5D(https://youtu.be/fBNz5xF-Kx4)"&gt;this crash course&lt;/a&gt; from TraversyMedia on Youtube. &lt;/p&gt;

&lt;p&gt;To get started setting up your server, you'll want to make a new folder in which you will be placing your project, and then &lt;code&gt;npm init&lt;/code&gt; to setup your &lt;code&gt;package.json&lt;/code&gt;. For this tutorial, I recommend running &lt;code&gt;npm init -y&lt;/code&gt; so you can skip the setup questions and get right to coding...&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="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;my-first-express-server
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;my-first-express-server
&lt;span class="nv"&gt;$ &lt;/span&gt;npm init &lt;span class="nt"&gt;-y&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you have your &lt;code&gt;package.json&lt;/code&gt;, you need to install Express&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="nv"&gt;$ &lt;/span&gt;npm i express 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And I also highly recommend including the &lt;a href="%5Bhttps://nodemon.io/%5D(https://nodemon.io/)"&gt;Nodemon&lt;/a&gt; utility in your &lt;code&gt;devDependencies&lt;/code&gt;. Nodemon automically restarts your server on save so that you don't have to repeatedly &lt;code&gt;^c&lt;/code&gt; and restart your server with every change.&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="nv"&gt;$ &lt;/span&gt;npm i &lt;span class="nt"&gt;-D&lt;/span&gt; nodemon
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;the &lt;code&gt;-D&lt;/code&gt; flag indicates that you specifically want this to be installed as a &lt;code&gt;devDependecy&lt;/code&gt; in your &lt;code&gt;package.json&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Next, add an &lt;code&gt;index.js&lt;/code&gt; file to your project folder. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;(now would be a good time to &lt;code&gt;git init&lt;/code&gt;, but first make sure you add your &lt;code&gt;node_modules&lt;/code&gt; to a &lt;code&gt;.gitignore&lt;/code&gt; file!)&lt;/em&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Now for the fun stuff! 🎉&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The first thing we need to do is &lt;code&gt;require('express')&lt;/code&gt; in our &lt;code&gt;index.js&lt;/code&gt;&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="s1"&gt;express&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;The coolest thing about Express, in my opinion, is that this &lt;code&gt;require&lt;/code&gt; is &lt;em&gt;all we need&lt;/em&gt; to set up our &lt;code&gt;"Hello World"&lt;/code&gt; server or a simple API! &lt;/p&gt;

&lt;p&gt;&lt;em&gt;if you want to serve static files (like HTML and CSS) using your server, you can add &lt;code&gt;require('path')&lt;/code&gt; at the top of &lt;code&gt;index.js&lt;/code&gt;. We'll cover this more later...&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;Now we need to set &lt;code&gt;express&lt;/code&gt; to a variable that we'll call (mostly) all of our other methods on to get our server working:&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;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="cm"&gt;/* it's pretty common for this variable to be called 'app' but you
can theoretically call it whatever you want! */&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, before we do anything else, we need to tell our &lt;code&gt;app&lt;/code&gt; what &lt;code&gt;PORT&lt;/code&gt; to listen on when we run the server. &lt;/p&gt;

&lt;p&gt;You &lt;em&gt;could&lt;/em&gt; tell your server to just use port &lt;code&gt;5000&lt;/code&gt; and be done with it, but it's good to plan ahead for eventually deployment! &lt;/p&gt;

&lt;p&gt;Once your server has been deployed, it's likely your deployment will tell your app to use a port stored in an &lt;code&gt;.env&lt;/code&gt; file. So we need to tell our &lt;code&gt;app&lt;/code&gt; to &lt;code&gt;listen&lt;/code&gt; on port &lt;code&gt;5000&lt;/code&gt; &lt;em&gt;or&lt;/em&gt; whatever port is being passed to the app in the &lt;code&gt;.env&lt;/code&gt; file...&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;PORT&lt;/span&gt; &lt;span class="o"&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="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;5000&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;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="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="s2"&gt;`Server running on 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="cm"&gt;/* app.listen() takes 2 arguements: the port you want to listen on, and a callback. Here we're passing a console.log() in the callback that will let us know what PORT server is running on */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;place this code at the bottom of your &lt;code&gt;index.js&lt;/code&gt; file...the rest of what we're about to write in &lt;code&gt;index&lt;/code&gt; will go between your &lt;code&gt;app&lt;/code&gt; variable declaration and your &lt;code&gt;PORT&lt;/code&gt; variable declaration&lt;/em&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  Let's take a quick trip to our &lt;code&gt;package.json&lt;/code&gt; ...
&lt;/h3&gt;

&lt;p&gt;So, remember when I had you install &lt;code&gt;nodemon&lt;/code&gt;? Now's the time to use it! &lt;/p&gt;

&lt;p&gt;Inside of your &lt;code&gt;package.json&lt;/code&gt; you're going to write 2 &lt;code&gt;"scripts"&lt;/code&gt;... &lt;/p&gt;

&lt;p&gt;First, we want a script called &lt;code&gt;dev&lt;/code&gt;, where we'll use &lt;code&gt;nodemon&lt;/code&gt; to run our &lt;code&gt;index.js&lt;/code&gt; file. Then we want to write a &lt;code&gt;"start"&lt;/code&gt; script that will be used to run the app once it's deployed:&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;"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;"nodemon index"&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 index"&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;/div&gt;



&lt;p&gt;&lt;em&gt;package.json&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Ok, cool, back to our &lt;code&gt;index.js&lt;/code&gt; ...
&lt;/h3&gt;

&lt;p&gt;We made it! It's time! We're &lt;em&gt;so&lt;/em&gt; close to "Hello World"! We're going to write our first Express &lt;code&gt;get&lt;/code&gt; request handler &lt;em&gt;right now&lt;/em&gt;! &lt;/p&gt;

&lt;p&gt;Here is the syntax for the get request:&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;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&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;/&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="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 goes here&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;index.js&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;First we call &lt;code&gt;app.get()&lt;/code&gt;, passing it the route we want to &lt;code&gt;get&lt;/code&gt; (in this case the root route &lt;code&gt;'/'&lt;/code&gt;) and a callback which will tell the server what to actually &lt;em&gt;do&lt;/em&gt; with this route. We pass the &lt;code&gt;req&lt;/code&gt; (request) and &lt;code&gt;res&lt;/code&gt; (response) to this callback. &lt;/p&gt;

&lt;p&gt;Getting our "Hello World" on the page is as simple as using the &lt;code&gt;res.send()&lt;/code&gt; function! You can pass strings to &lt;code&gt;res.send()&lt;/code&gt; (typically this would be the path to the file you want to server on the specified route) but for now we're going to pass a string of HTML:&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;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&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;/&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="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="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;h1&amp;gt;Hello World!&amp;lt;/h1&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; 
        &lt;span class="c1"&gt;// or whatever your favorite hello world is!&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;Now, from your CLI we want to run the &lt;code&gt;dev&lt;/code&gt; script we wrote in our &lt;code&gt;package.json&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm run dev&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;Then open up your favorite browser and navigate to &lt;code&gt;localhost:5000&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;You did it! You wrote your first Express server!!  🎉&lt;/p&gt;

&lt;p&gt;Do a quick dance party to celebrate, and then go back into your &lt;code&gt;res.send()&lt;/code&gt; function and add a few more things to your HTML string. Save your file and watch as &lt;code&gt;nodemon&lt;/code&gt; does the behind-the-scenes magic to rerun your server and serve the changes you just made &lt;strong&gt;live&lt;/strong&gt;! &lt;/p&gt;

&lt;h3&gt;
  
  
  Bonus: Let's serve an actual HTML file!
&lt;/h3&gt;

&lt;p&gt;First, we need to make that HTML file, and put it in the right place. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;( this is also when we want to make sure we included &lt;code&gt;require('path')&lt;/code&gt; at the top of our file )&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;First, add a &lt;code&gt;public&lt;/code&gt; folder inside of your servers root folder. Then add a file inside of that folder called &lt;code&gt;index.html&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now, go ahead and put anything you want in &lt;code&gt;index.html&lt;/code&gt;. The fastest option is to add the HTML boilerplate, and copy over what you had in your string of HTML from your &lt;code&gt;res.send()&lt;/code&gt; function. &lt;/p&gt;

&lt;p&gt;Back in &lt;code&gt;index.js&lt;/code&gt;, comment out the &lt;code&gt;res.send()&lt;/code&gt; inside of your &lt;code&gt;app.get()&lt;/code&gt; function. &lt;/p&gt;

&lt;p&gt;We're going to replace that line with this:&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;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&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;/&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="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;// res.send("&amp;lt;h1&amp;gt;Hello World!&amp;lt;/h1&amp;gt;")&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sendFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;public&lt;/span&gt;&lt;span class="dl"&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;index.html&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;Now, we are using the function &lt;code&gt;.sendFile()&lt;/code&gt; to tell serve the file &lt;code&gt;index.html&lt;/code&gt; inside of the &lt;code&gt;public&lt;/code&gt; folder, inside of the current directory (the root of our server) &lt;/p&gt;

&lt;p&gt;We can also tell Express to server any static file on its own route:&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;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;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;static&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;public&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;That's a lot of function nesting! Essentially what's happening here is:&lt;/p&gt;

&lt;p&gt;the &lt;code&gt;app.use()&lt;/code&gt; function tells our app to &lt;code&gt;use&lt;/code&gt; the &lt;code&gt;express.static()&lt;/code&gt; function to set the path for static files in our app to &lt;code&gt;path.join(__dirname, 'public')&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;code&gt;__dirname&lt;/code&gt; indicates the current file directory, so we're telling our &lt;code&gt;app&lt;/code&gt; that the static files live inside a folder called &lt;code&gt;public&lt;/code&gt; inside of the current directory.&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;Now, if you added another file inside of &lt;code&gt;public&lt;/code&gt; called &lt;code&gt;about.html&lt;/code&gt; and then navigate to &lt;code&gt;localhost:5000/about.html&lt;/code&gt; you'll be served the contents of your &lt;code&gt;about.html&lt;/code&gt; file! With one line of code, we're able to serve &lt;em&gt;any&lt;/em&gt; file we add to our &lt;code&gt;public&lt;/code&gt; folder! &lt;/p&gt;

&lt;p&gt;I hope you had fun setting up your Express server with me! Now go forth and make me something cool! Make sure you tweet @ me if you use this tutorial to build your server. I would love to see what you build! &lt;/p&gt;

&lt;p&gt;Next up, we'll be covering how to hook in a database with our Express backend, and serving JSON to turn our server into a REST API! &lt;br&gt;
&lt;em&gt;(keep your eyes pealed for the next post in this series coming soon...)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You can find more of my work &lt;a href="//dev.to/thecodepixi"&gt;here on DEV&lt;/a&gt;, and on: &lt;br&gt;
&lt;a href="//www.twitter.com/thecodepixi"&gt;Twitter&lt;/a&gt;&lt;br&gt;
&lt;a href="//www.github.com/thecodepixi"&gt;GitHub&lt;/a&gt;&lt;br&gt;
and &lt;br&gt;
&lt;a href="//www.codepen.com/thecodepixi"&gt;CodePen&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;xx - Pixi&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>express</category>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Building An App I'll Actually Use</title>
      <dc:creator>Emmy | Pixi</dc:creator>
      <pubDate>Thu, 19 Mar 2020 01:30:33 +0000</pubDate>
      <link>https://dev.to/thecodepixi/building-an-app-i-ll-actually-use-7df</link>
      <guid>https://dev.to/thecodepixi/building-an-app-i-ll-actually-use-7df</guid>
      <description>&lt;p&gt;It's here, it's here, it's finally here! My final Flatiron project has arrived!! &lt;/p&gt;

&lt;p&gt;I hope you're ready to be underwhelmed, y'all. This project process has been a DOOZY, from personal health problems to a massive global public health crisis, there was a lot that got in the way of this project. BUT, I finally built something that I think is a tool I'll actually use, and something I'm really excited to keep working on. It's an absolute MVP, with emphasis on the M, but I'm still glad to have gotten it done. &lt;/p&gt;

&lt;p&gt;In the run-up to this project, I was &lt;em&gt;stumped&lt;/em&gt; as for what to build. I had really struggled with the React/Redux curriculum and just felt at a total loss for any ideas on what to build because the idea of building a fully functional React project from nothing felt...scary. But we all know fear is where we grow. &lt;/p&gt;

&lt;p&gt;In talking to my advisor and other students, the recommendation that kept coming up was to build a tool; something you (I) would actually use and find useful in our (my) everyday lives. As someone with chronic health issues who sees (what feels like) an endless stream of doctors and specialists, it can get really difficult to keep track of when I saw which doctor, what was discussed, what new treatment plans we put into place, and whether I need to follow up with them. &lt;/p&gt;

&lt;p&gt;And so, "Doctor's Orders" was born. So far, it's a fairly simple SPA, with 3 routes supplied by React Router. A main home route, a show page, and a new "order" form. You can track your which doctor you saw, their specialty, the date of the appointment, the appointment type (from a set drop-down list), any test results or treatment notes, and whether you need to follow up with your doctor. &lt;/p&gt;

&lt;p&gt;My biggest challenge with this project came from working with Redux, and using it to properly update state across the application. I ran into an issue with fetching data from the database too frequently, and incorrectly updating state in my reducer. It was &lt;em&gt;super&lt;/em&gt; frustrating, but such a great learning experience. The biggest thing I think I learned from this project was really tracking and controlling state across my entire application, and keeping track of when and how things are being changed, updated, removed, or added, and keeping it in sync with the changes to my database. &lt;/p&gt;

&lt;p&gt;I also decided to work with Semantic UI for styling on this project, which I had never used before and really enjoyed working with. The built-in library of icons was super convenient and a nice perk, and using a library like Semantic helped me to really quickly add cohesive styling with minimal effort. &lt;/p&gt;

&lt;p&gt;You can see the code for my project on GitHub, and I'm hoping to get it deployed to Heroku soon! &lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A9-wwsHG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/thecodepixi"&gt;
        thecodepixi
      &lt;/a&gt; / &lt;a href="https://github.com/thecodepixi/doctors_orders"&gt;
        doctors_orders
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      React/Redux + Rails Final Project for Flatiron School
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;I have a TON of ideas for ways to expand this project, including: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;alerts for following up with doctors on a specific date&lt;/li&gt;
&lt;li&gt;a field for follow-up questions you want to ask your doctor&lt;/li&gt;
&lt;li&gt;a symptom tracker &lt;/li&gt;
&lt;li&gt;a test results tracker &lt;/li&gt;
&lt;li&gt;sorting / filtering options for viewing previous doctor's orders by doctor &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cross your fingers for me as I go into the assessment process for this project. Graduation is on the horizon! &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>codenewbie</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
