<?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: Bennett Dungan</title>
    <description>The latest articles on DEV Community by Bennett Dungan (@beznet).</description>
    <link>https://dev.to/beznet</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%2F37228%2Fc9d132a0-ffcd-4057-8da8-e16f7e961b44.jpeg</url>
      <title>DEV Community: Bennett Dungan</title>
      <link>https://dev.to/beznet</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/beznet"/>
    <language>en</language>
    <item>
      <title>Tydii - Decluttering App</title>
      <dc:creator>Bennett Dungan</dc:creator>
      <pubDate>Mon, 08 Jun 2020 14:46:09 +0000</pubDate>
      <link>https://dev.to/beznet/tydii-decluttering-app-4cfg</link>
      <guid>https://dev.to/beznet/tydii-decluttering-app-4cfg</guid>
      <description>&lt;p&gt;As a follow-up to my &lt;a href="https://dev.to/beznet/a-definitive-guide-for-escaping-tutorial-hell-102c"&gt;How to Escape Tutorial Hell&lt;/a&gt; article, I referenced this little app I was building off to the side to use as my showcase example. This app is the product of following through with that whole process I laid out.&lt;/p&gt;

&lt;p&gt;Check it out here: &lt;a href="https://www.tydiiup.com" rel="noopener noreferrer"&gt;https://www.tydiiup.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's a mixture of my interest in minimalism and as something to practice using NextJS and React. The idea, in a nutshell, is that people have emotional ties to their belongings which makes getting rid of certain items harder than others. The app allows the user to rate each individual item they are on the fence about keeping on a 'happiness' scale denoted by facial expressions. Once you're done with that, it filters out the things you weren't completely happy with and brings you to a dash that helps you keep track of the items that you're either selling or donating (or throwing away, lol).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/IblcVxzvNAfo9PteLz/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/IblcVxzvNAfo9PteLz/giphy.gif" alt="tydii item input"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The part I upgraded the past couple months was implementing a user login system which encrypts and stores user data in a MongoDB database. I then built a dashboard that helps people keep track of their things as they get rid of them.&lt;/p&gt;

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

&lt;p&gt;It's by no means perfect, but I've come to a point in this project that Im okay with some of the imperfections and will circle back to them at a later date. &lt;/p&gt;

&lt;p&gt;I essentially built it for myself when I go through bouts of decluttering. I hope some of you also find it useful as well. Feel free to (&lt;em&gt;deep breath...&lt;/em&gt;) check out the &lt;a href="https://github.com/Beznet/tydii" rel="noopener noreferrer"&gt;code on Github&lt;/a&gt;. Im sure it could use lots of improvements!&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>opensource</category>
      <category>productivity</category>
    </item>
    <item>
      <title>A Definitive Guide for Escaping Tutorial Hell</title>
      <dc:creator>Bennett Dungan</dc:creator>
      <pubDate>Sat, 29 Feb 2020 23:59:50 +0000</pubDate>
      <link>https://dev.to/beznet/a-definitive-guide-for-escaping-tutorial-hell-102c</link>
      <guid>https://dev.to/beznet/a-definitive-guide-for-escaping-tutorial-hell-102c</guid>
      <description>&lt;p&gt;There's quite a few articles floating around the interwebs in regards to the whole "tutorial hell" dilemma that many developers face. They tell you to apply what you've learned by giving you some ideas for projects and how to contribute to open source but I feel those are the end goals. What I usually find missing is how you go from an endless cycle of tutorials to successfully applying that knowledge to real world projects. I've made my own little system for escaping the never ending spiral of the tutorial hell hole that I think some of you might find beneficial.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is tutorial hell and how did I get here?
&lt;/h2&gt;

&lt;p&gt;One thing we need to have a clear understanding of before we dive into the strategy is why we get stuck in this predicament to begin with. I personally find myself in this cycle sometimes so I know how alluring it can be to build something flashy in a perfectly sanitized environment that the instructor has laid out for you every step of the way. That's one of the seductive things about tutorials though, they are these pristinely engineered walkthroughs of something that has no gotchas along the way because you're being held by the hand. This gives you a perpetual sense of accomplishment when we all know coding is generally all about pushing through roadblocks and constant challenges.&lt;/p&gt;

&lt;p&gt;Don't get me wrong, I devour tutorials like crazy because it's how I personally learn to use a tool or language. There's a distinction that you need to make though, you either become a 'tut slut' or you know when to pump the breaks and use that knowledge for something useful before it goes stale.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: List any app idea you've ever had
&lt;/h2&gt;

&lt;p&gt;The first thing to do after binging a whole season of Wes Bos n' Friends or the Coding ChooChoo Train is to just jot down a list of apps that you think would be cool. Like literally anything, the sky's the limit at this moment. Your knowledge need not apply, just write down anything you think would be fun or useful to use in your own life. I usually find the most inspiration by thinking of small annoyances I have each day and think if there is any sort of usefulness an application could bring to the table. This might take a few days too, I rarely have a good idea the first time I think about this. Sometimes it’ll hit me when I'm doing something completely irrelevant. Here’s an example list of items I’ve jotted down:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;minimalism app for getting rid of items&lt;/li&gt;
&lt;li&gt;astronomy events reminder app&lt;/li&gt;
&lt;li&gt;drive your roomba manually app&lt;/li&gt;
&lt;li&gt;hide everything except events on facebook&lt;/li&gt;
&lt;li&gt;ebay price history from pictures&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 2: List your tutorials
&lt;/h2&gt;

&lt;p&gt;Now you've got this little list of cool app ideas, nice! Before we whittle that list down some, we need to make another list but this time it's of all the tutorials you recently completed. Don't worry if you didn't finish the tutorial either, even if you got 20% of the way through just jot that down as well. Here’s the most recent ones I’ve done:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;API Design in Node&lt;/li&gt;
&lt;li&gt;Typescript Fundamentals &lt;/li&gt;
&lt;li&gt;React todo walkthrough&lt;/li&gt;
&lt;li&gt;Design for Developers&lt;/li&gt;
&lt;li&gt;Playing around with React Dnd&lt;/li&gt;
&lt;li&gt;JWT Authentication and Login&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 3: Pair the apps to the tutorials
&lt;/h2&gt;

&lt;p&gt;In this phase we need to take each app and find any tutorial that we think would be beneficial in building it out. In the end we will see which app idea has the most relevance from our recent learning cycle:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;minimalism app for getting rid of items - &lt;strong&gt;4 total&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Design for developers&lt;/li&gt;
&lt;li&gt;Typescript fundamentals&lt;/li&gt;
&lt;li&gt;React todo walkthrough&lt;/li&gt;
&lt;li&gt;JWT auth and login&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;astronomy events reminder app - &lt;strong&gt;4 total&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Design for developers&lt;/li&gt;
&lt;li&gt;Typescript fundamentals&lt;/li&gt;
&lt;li&gt;JWT auth and login&lt;/li&gt;
&lt;li&gt;Api design in node&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;drive my Roomba manually app - &lt;strong&gt;0 total&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;(moonshot idea, no realistic overlap from recent tutorials)&lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;hide everything except events on facebook - &lt;strong&gt;1 total&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Design for developers&lt;/li&gt;
&lt;/ol&gt;


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

&lt;p&gt;eBay price history from pictures - &lt;strong&gt;3 total&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Api design in node&lt;/li&gt;
&lt;li&gt;Typescript fundamentals&lt;/li&gt;
&lt;li&gt;Design for developers&lt;/li&gt;
&lt;/ol&gt;


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

&lt;p&gt;&lt;em&gt;Note: You may not really know what types of tools, libraries, frameworks are required for your app idea and that’s ok! Just put down anything you’ve recently learned that you think may even remotely benefit you during the build process.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Pick the most exciting app/tutorial combo
&lt;/h2&gt;

&lt;p&gt;In this step we want to analyze our top app ideas with the most tutorials and decide which of these are the most interesting and/or inspiring to work on. In my case, my top two are “astronomy events reminder app” and “minimalism app for getting rid of items” . I really love astronomy and would love an app to remind me of specific events (meteor showers, ISS overhead, full moon, etc), but this would be more of a  ‘for fun’ app. The minimalism app would actually help me solve a problem I have been having lately and that is trying to decide what items to keep or give away. In this example I decide to go with the minimalism app because I like the idea of solving a real issue.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Strip it to the essential building blocks
&lt;/h2&gt;

&lt;p&gt;Right on, so we have an app idea that has a solid foundation of tutorials and some inspiration. This step is to lay out the high level functionality of our app and see where the tutorials we completed can help us out:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Minimalism App:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Needs to list out items with add/delete feature:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I can use the React Todo tutorial to build out the whole list feature. This is the base feature for the application so I can either take the React Todo app I built and just modify it or reference the tutorial again as I am adapting it for my specific needs. &lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;Needs a rating system for each item&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The rating system isn’t something I’ve specifically tackled, but it’s something I know I can figure out along the way.&lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;User login and authentication to save list:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The JWT Auth Login tutorial I did can help me out for making a user login system&lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;Simple but inviting design&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Not an essential, but I’d like for the app to be appealing to use so I can use the Design tutorial for this part&lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;I’ve got around 75% of the application covered by the tutorials I’ve completed, the other 25% is something I can just use some Google-Fu to cover. &lt;/p&gt;

&lt;p&gt;In the end, I actually made this app with the above process. You can view it &lt;a href="https://tydiiup.com/"&gt;HERE.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;I haven’t gotten to adding user auth just yet but the majority of my idea was completed using the above steps.&lt;sup&gt;&lt;/sup&gt;&lt;/sup&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I hope by breaking down your tutorials into building blocks for an application proves to be useful. You’re probably more ready to build that app idea you’ve always had, you just need to take time to analyze the app's essential functionality and identify all the areas you’ve already covered in tutorials. You’re never going to know 100% of everything needed, but that’s literally with everything you’ll ever do as a developer.&lt;/p&gt;

&lt;p&gt;Since most of you reading this are looking to escape the tutorial hell spiral, I’ve framed this system as something to do on your first venture of escaping that void. What I do now is actually decide on something I want to build and then figure out what I know/don’t know and watch or read a few guides on those unknowns (but not too much, just enough to get 80% of the way there). I’d love to know what everyone else’s strategies are so feel free to drop a comment down below.&lt;/p&gt;




&lt;p&gt;♫ Writing Music ♫&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://open.spotify.com/artist/053q0ukIDRgzwTr4vNSwab"&gt;Grimes - Miss Anthropocene&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://open.spotify.com/playlist/37i9dQZF1DX9sIqqvKsjG8"&gt;Instrumental Study - Spotify Playlist&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://open.spotify.com/artist/4frXpPxQQZwbCu3eTGnZEw"&gt;Thundercat&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;sup&gt;I thought it would be fun to just share some of the tunes I listen to while writing :) &lt;sup&gt;&lt;/sup&gt;&lt;/sup&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>productivity</category>
      <category>career</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Review: 100 Hours of Front End Masters</title>
      <dc:creator>Bennett Dungan</dc:creator>
      <pubDate>Sun, 16 Feb 2020 21:34:54 +0000</pubDate>
      <link>https://dev.to/beznet/review-100-hours-of-front-end-masters-5akd</link>
      <guid>https://dev.to/beznet/review-100-hours-of-front-end-masters-5akd</guid>
      <description>&lt;p&gt;&lt;em&gt;NOTE: I have no affiliation with Front End Masters nor any of the people mentioned in the review. All of the opinions are solely my own.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I've been lucky enough to spend over 100 hours using the Front End Masters program for the past year and I've decided that I've gotten a good enough feel for the quality of it to give an honest review. Being that the course can run a few hundred $$$, a lot of people might want to know if its worth the money. Hopefully, I can make things a bit clearer for those of you who are undecided. &lt;/p&gt;

&lt;p&gt;I've divided this review into 4 sections: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Content&lt;/li&gt;
&lt;li&gt;Teaching Style&lt;/li&gt;
&lt;li&gt;Suggested Improvements&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  CONTENT
&lt;/h2&gt;

&lt;p&gt;One of the main reasons I enjoy FEM is the &lt;a href="https://frontendmasters.com/courses" rel="noopener noreferrer"&gt;sheer amount of content&lt;/a&gt; that is available. They cover everything from Node, React, Vue, Angular, general CS, GraphQL, Javascript, Python, CSS, SVGs, Design, CSS, etc etc. They do a great job at keeping the range of topics very broad and for someone like me, whose getting their feet wet in this whole industry, the diversity of content has been fantastic. &lt;/p&gt;

&lt;p&gt;There definitely is more focus on certain frameworks/technologies over others though. I develop in React and there's a ton of React content but for someone who wants to focus on Vue, the amount of content for that is marginal in comparison. Luckily, you can browse their entire catalogue of courses to determine if they have an adequate amount of lessons on the things you would like to learn before you sign up. The length of the lessons vary a bit but almost all of them are long-format ranging between 3 to 10 hours in length. As long as the topics being taught aren't too broad, I've found that you can get through quite a bit of content over this time-frame. &lt;/p&gt;

&lt;h2&gt;
  
  
  Teaching Style
&lt;/h2&gt;

&lt;p&gt;The style of teaching is in front of a live classroom. While this may or may not be conducive to your learning style, I find that the interaction between the teachers and students helps to fill in some gaps that I typically don't get during traditional video lessons. Most of the teachers are full-time developers themselves so they bring a ton of real-world scenarios and perspectives into their teaching style. I just finished up a course called Full Stack for Front End Developers by &lt;a href="https://twitter.com/JemYoung" rel="noopener noreferrer"&gt;Jem Young&lt;/a&gt; who works at Netflix. He sprinkles in bits of information about how Netflix utilizes some of the technologies being taught and that added a whole new layer of knowledge that connects real-world scenarios to the things you're learning in the classroom.&lt;/p&gt;

&lt;p&gt;One of the best things about FEM is when the teachers actively get the students involved. I know we all hated it when teachers called on us in school to answer questions, but as a 3rd party viewer its extraordinarily helpful to have these students answer questions you may have been scratching your head about yourself. The students sitting in the live audience usually range from beginner to advanced so in every class you'll get a range of questions being brought up. One of the grand masters of getting the students involved (along with killer white-boarding skills) is &lt;a href="https://twitter.com/willsentance" rel="noopener noreferrer"&gt;Will Sentance&lt;/a&gt;. &lt;/p&gt;

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

&lt;p&gt;I believe this guy should be one of the benchmarks when it comes to how people should teach code. The enthusiasm mixed with step-by-step drawings and explanations broke a mental barrier I had on a lot of JS concepts. Many of the teachers are great about giving detailed explanations on how to do X without going at breakneck speeds, which is a plus for me.&lt;/p&gt;

&lt;h2&gt;
  
  
  Suggested Improvements
&lt;/h2&gt;

&lt;p&gt;As with everything, the program isn't for everyone and could be improved. One of the great things I was touting earlier, the live teacher/student interaction, doesn't actually happen on all courses taught. Some of the teachers don't really get the students involved and I find that these lessons have a lot less retention for me. I think the FEM organizers should make it mandatory that the teachers have some level of interaction with the students because it makes a huge difference for the 3rd party viewers. &lt;/p&gt;

&lt;p&gt;Another issue I've had is that there doesn't seem to be an outlet for students to interact with one another and/or find help with the courses. One thing I enjoy about &lt;a href="https://wesbos.com/" rel="noopener noreferrer"&gt;Wes Bos's paid courses&lt;/a&gt; are the Slack groups. There's always a handful of people able to help you if you're ever stuck in one of his lessons. If you get stuck on a FEM lesson, you're kinda out of luck unfortunately.&lt;/p&gt;

&lt;p&gt;One thing in regards to accessibility is the closed captions. Its great that they have them on every video but sometimes I notice misinterpretations of what is being talked about. IE. "git" will be translated to "get" or "vue" to "view". I can imagine a hearing impaired dev might get a bit confused if they're solely relying on the captions so its definitely one area that could be improved. &lt;/p&gt;

&lt;p&gt;This one is kind of nit picking and almost counter-intuitive given that the name of the program is 'Front End Masters' but I really wish there was more back-end courses. As I've gone through a bit of the front-end technologies, I've gotten more and more interested in the back-end. I love the teaching style and besides the Full Stack course I mentioned before with Jem Young, there really isn't a whole lot of back-end lessons. Again, I know how counter-intuitive this sounds but its an option I wish I had given that I enjoy the format so much. &lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion!
&lt;/h2&gt;

&lt;p&gt;Should you buy the program? Well if you enjoy the live &amp;amp; interactive classroom teaching style then yes, I find it to be a fantastic resource and worth the money. The variety of subjects and teachers keeps things fresh and the quality of the content is always impressive.&lt;/p&gt;

&lt;p&gt;As someone who just started out in this industry, I've found the content fascinating and I'm always looking forward to the newer courses that get released. If you have any specific questions about the program that I didn't cover, feel free to ask me in the comments below. &lt;/p&gt;

</description>
      <category>frontendmasters</category>
      <category>review</category>
      <category>resources</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Build a REST API with Node, Express &amp; MongoDB!</title>
      <dc:creator>Bennett Dungan</dc:creator>
      <pubDate>Thu, 01 Aug 2019 21:31:45 +0000</pubDate>
      <link>https://dev.to/beznet/build-a-rest-api-with-node-express-mongodb-4ho4</link>
      <guid>https://dev.to/beznet/build-a-rest-api-with-node-express-mongodb-4ho4</guid>
      <description>&lt;p&gt;In this project we will be creating a way for people to subscribe, update, retrieve and delete data on Youtube accounts. We’ll do this by coding a REST API that lets users interact with our Youtube database by defining what info our database will accept and how it goes about manipulating that data depending on what a user would like to do.&lt;/p&gt;

&lt;p&gt;A big shoutout to &lt;a href="https://www.youtube.com/channel/UCFbNIlppjAuEX4znoulh0Cw" rel="noopener noreferrer"&gt;Web Dev Simplified&lt;/a&gt; for the knowledge he was able to pass along in helping me create this tutorial. If you’d prefer to see a video walkthrough for this then I highly recommend checking out Web Dev Simplified’s tutorial &lt;a href="https://youtu.be/fgTGADljAeg" rel="noopener noreferrer"&gt;HERE&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  MY GITHUB REPO
&lt;/h3&gt;

&lt;p&gt;If you get stuck or think you did something wrong and can’t quite figure it out, refer to my Github Repo of the completed application here: &lt;a href="https://github.com/Beznet/node-api" rel="noopener noreferrer"&gt;https://github.com/Beznet/node-api&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Project and Dependency Setup
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Important Prerequisite:&lt;/strong&gt; Make sure you already have MongoDB installed and setup on your machine before starting this tutorial. Here is a link to a guide that MongoDB provides on their website: &lt;a href="https://docs.mongodb.com/manual/administration/install-community/" rel="noopener noreferrer"&gt;MongoDB Installation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First, let’s open our terminal and create a new directory for this project. Now in our terminal type &lt;code&gt;npm init&lt;/code&gt; to start and just leave all fields blank for the time being by pressing ENTER through each question. Next we want to install &lt;a href="https://expressjs.com/" rel="noopener noreferrer"&gt;Express&lt;/a&gt; and &lt;a href="https://mongoosejs.com/" rel="noopener noreferrer"&gt;Mongoose&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i express mongoose&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then once those two are finished being installed we need to also install &lt;a href="https://www.npmjs.com/package/dotenv" rel="noopener noreferrer"&gt;&lt;code&gt;dotenv&lt;/code&gt;&lt;/a&gt; and &lt;a href="https://nodemon.io/" rel="noopener noreferrer"&gt;&lt;code&gt;nodemon&lt;/code&gt;&lt;/a&gt; by entering:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i --save-dev dotenv nodemon&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: --save-dev from above will save development-only dependencies without saving them to production&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;dotenv&lt;/code&gt; will allow us to pull in environment variables from a &lt;code&gt;.env&lt;/code&gt; file and nodemon will update our local server each time we save&lt;/p&gt;

&lt;p&gt;When we ran &lt;code&gt;npm init&lt;/code&gt; earlier it created a &lt;code&gt;package.json&lt;/code&gt; file. In this file under the scripts we want to replace that ‘test’ script with our own script that starts our server with &lt;code&gt;nodemon&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="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;devStart&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 server.js&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;h2&gt;
  
  
  Setting Up Our Server
&lt;/h2&gt;

&lt;p&gt;Ok now we get to create our first file called &lt;code&gt;server.js&lt;/code&gt; . Once created, at the top of the file we want to include all of the dependencies that we will need for our project:&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="nf"&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;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="nf"&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;mongoose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;mongoose&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;When we want to test and make sure our server is working, we will run this function to listen on port 3000 and log a string if its successful:&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="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;server started&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;At this point our server.js file should look like 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="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="nf"&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;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="nf"&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;mongoose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;mongoose&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="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;server started&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;h2&gt;
  
  
  Connecting to Our Database
&lt;/h2&gt;

&lt;p&gt;This next chunk of code in our &lt;code&gt;server.js&lt;/code&gt; file starting with &lt;code&gt;mongoose.connect&lt;/code&gt; is how we connect to the database. I’ll explain it line by line:&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="nf"&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;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="nf"&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;mongoose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;mongoose&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;mongoose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&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;DATABASE_URL&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;db&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="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;error&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;error&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="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;once&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;open&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;connected to database&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="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;server started&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 first line allows us to connect to the database using Mongoose. You may be wondering what &lt;code&gt;DATABASE_URL&lt;/code&gt; is, this is the location we want for our database which I have defined in our &lt;code&gt;.env&lt;/code&gt; file. If you haven’t created a &lt;code&gt;.env&lt;/code&gt; file, now would be a good time and then you can set the &lt;code&gt;DATABASE_URL&lt;/code&gt; there:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;// .env file

&lt;span class="nv"&gt;DATABASE_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;mongodb://localhost/subscribers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After we have our &lt;code&gt;DATABASE_URL&lt;/code&gt; defined in our &lt;code&gt;.env&lt;/code&gt; let's hop back to our &lt;code&gt;server.js&lt;/code&gt; file. Now to reference variables in our &lt;code&gt;.env&lt;/code&gt; file we need to require the &lt;code&gt;dotenv&lt;/code&gt; package at the top of our server.js 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="nf"&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;dotenv&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;config&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After we get that package required the line of…&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;mongoose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&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;DATABASE_URL&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;…will now function appropriately.&lt;/p&gt;

&lt;p&gt;Moving on, we have set &lt;code&gt;db&lt;/code&gt; to &lt;code&gt;mongoose.connection&lt;/code&gt; as a syntactically easier way to reference our database. Next, we’ve defined what happens when the database encounters an error, which is to log the &lt;code&gt;error&lt;/code&gt; itself. If there’s no error we want to log the string of &lt;code&gt;connected to database&lt;/code&gt; to our terminal.&lt;/p&gt;

&lt;p&gt;Ok! That’s a lot of stuff. So to sort of put everything together our &lt;code&gt;server.js&lt;/code&gt; file should now look like 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="nf"&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;dotenv&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;config&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;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;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="nf"&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;mongoose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;mongoose&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;mongoose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&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;DATABASE_URL&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;db&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="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;error&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;error&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="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;once&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;open&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;connected to database&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="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;server started&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;h2&gt;
  
  
  Let’s Test Our Database Connection!
&lt;/h2&gt;

&lt;p&gt;At this point we can now test out our connection to the database to make sure everything is working smoothly. In our terminal, let’s go ahead and start our database by typing &lt;code&gt;mongod&lt;/code&gt; and then in another terminal tab let’s start our server with &lt;code&gt;npm run devStart&lt;/code&gt;. If all went well, we should get these messages after we start our server:&lt;/p&gt;

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

&lt;p&gt;Cool! We’ve successfully started our server and our database appears to be operational.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up Our Server to Accept JSON
&lt;/h2&gt;

&lt;p&gt;In our same &lt;code&gt;server.js&lt;/code&gt; file we want to tell Express that it should accept JSON. Lets put this line of code in between our ‘database is open’ line of code and the ‘listen on port 3000’ line:&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="p"&gt;...&lt;/span&gt;
&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;once&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;open&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;connected to database&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="nf"&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="nf"&gt;json&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="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3005&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;server started&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;The &lt;code&gt;.use&lt;/code&gt; is middleware that allows you to run code when the server gets a request but before it gets passed to your routes. So in this instance we’re telling Express to accept JSON as the data format.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating Our Routes Folder &amp;amp; File
&lt;/h2&gt;

&lt;p&gt;Let’s create a new directory for our routes to live in called &lt;code&gt;routes&lt;/code&gt; and then a file in this directory called &lt;code&gt;subscribers.js&lt;/code&gt; . Inside of this file is where we will define how the server should handle the data when it receives a GET, POST or PATCH request.&lt;/p&gt;

&lt;p&gt;But before we start creating those, lets switch back to our &lt;code&gt;server.js&lt;/code&gt; file and tell the server that we now have routes that it needs to handle and use. These next two lines of code are actually the last ones we need for our &lt;code&gt;server.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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;subscribersRouter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;./routes/subscribers&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="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/subscribers&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;subscribersRouter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here’s the full &lt;code&gt;server.js&lt;/code&gt; file with the new lines of code added:&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="nf"&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;dotenv&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;config&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;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;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="nf"&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;mongoose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;mongoose&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;mongoose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&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;DATABASE_URL&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;db&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="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;error&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;error&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="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;once&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;open&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;connected to database&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="nf"&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="nf"&gt;json&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;subscribersRouter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;./routes/subscribers&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="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/subscribers&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;subscribersRouter&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="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3005&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;server started&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;If something is missing or incorrect, right now is a great checkpoint to make sure you’ve got everything updated with the above. Give yourself a pat on the back for getting this far! We’re getting onto the fun stuff next…&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up Our Routes
&lt;/h2&gt;

&lt;p&gt;Now that our server file is all setup, let us now switch gears to our new &lt;code&gt;subscribers.js&lt;/code&gt; routes file. To start, let us require Express and define the &lt;code&gt;express.router()&lt;/code&gt; function on a variable called &lt;code&gt;router&lt;/code&gt; . While we’re at it let’s add our &lt;a href="https://www.sitepoint.com/understanding-module-exports-exports-node-js/" rel="noopener noreferrer"&gt;module export function&lt;/a&gt; as well at the very bottom:&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="nf"&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;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;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Before we get into the code, let’s get an understanding of what we exactly want to do with our routes. Since we’re trying to see and artificially create new subscribers on Youtube, we need this set of criteria:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Route for getting all subscribers&lt;/li&gt;
&lt;li&gt;Route for getting one subscriber&lt;/li&gt;
&lt;li&gt;Route for creating one subscriber&lt;/li&gt;
&lt;li&gt;Route for updating one subscriber&lt;/li&gt;
&lt;li&gt;Route for deleting one subscriber&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now let’s start each of the bullet points above with the basic framework depending on if its a GET, POST or PATCH 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="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="nf"&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;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;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;// Get all subscribers&lt;/span&gt;
&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&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="p"&gt;})&lt;/span&gt;

&lt;span class="c1"&gt;// Get one subscriber&lt;/span&gt;
&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&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;/: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="p"&gt;})&lt;/span&gt;

&lt;span class="c1"&gt;// Create one subscriber&lt;/span&gt;
&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&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="p"&gt;})&lt;/span&gt;

&lt;span class="c1"&gt;// Update one subscriber&lt;/span&gt;
&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;patch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&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="p"&gt;})&lt;/span&gt;

&lt;span class="c1"&gt;// Delete one subscriber&lt;/span&gt;
&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&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="p"&gt;})&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;The GET, POST and DELETE methods should look familiar but if not here’s a little &lt;a href="https://www.restapitutorial.com/lessons/httpmethods.html" rel="noopener noreferrer"&gt;refresher on them&lt;/a&gt; . The one thing that might look weird is the PATCH method. The PATCH method is being used here instead of the more traditional PUT method because we only want to use this to update pieces of the subscriber’s information and not all the information of the subscriber.&lt;/p&gt;

&lt;p&gt;You also may have noticed that we include &lt;code&gt;/:id&lt;/code&gt; in most of our parameters. This is for the routes that are requesting an action to be taken on a single subscriber thus we need that subscriber’s unique ID.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing Out Our API
&lt;/h2&gt;

&lt;p&gt;Let’s take a little break from our routes and test out our API with what we have so far. Inside of our ‘Get all subscribers’ route, let’s send text to our server:&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;// Get all subscribers&lt;/span&gt;

&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&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="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello World&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 for testing our API, I am going to use a Visual Studio Code extension called &lt;a href="https://marketplace.visualstudio.com/items?itemName=humao.rest-client" rel="noopener noreferrer"&gt;REST Client&lt;/a&gt;. If you do not have VS Code then you can use another program called &lt;a href="https://www.getpostman.com/" rel="noopener noreferrer"&gt;Postman&lt;/a&gt; that will also aid in testing the API. For this tutorial I will be using just REST Client in VS Code.&lt;/p&gt;

&lt;p&gt;Once you have the REST Client extension installed, let’s create a new file in our &lt;code&gt;routes&lt;/code&gt; folder for us to run our tests and call it &lt;code&gt;route.rest&lt;/code&gt;. It needs to end in &lt;code&gt;.rest&lt;/code&gt; or else it will not work correctly with REST Client.&lt;/p&gt;

&lt;p&gt;Great so now let’s write a test GET call to our server inside of our &lt;code&gt;route.rest&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET http://localhost:3000/subscribers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure you have &lt;code&gt;/subscribers&lt;/code&gt; after the 3000. Now if you hover above that line you just wrote, you should see ‘Send Request’ appear above it. Click that and watch on the right hand side of your screen for the result. If all went well, it should look something like this:&lt;/p&gt;

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

&lt;p&gt;On line 9, we can see that the server sent back ‘hello world’. This means our API is working correctly! Ok so we’ve done a lot so far, let’s take a hydration break and then we’ll get started with models.&lt;/p&gt;

&lt;h2&gt;
  
  
  Making the Model
&lt;/h2&gt;

&lt;p&gt;Let’s go ahead and setup our model and the schema inside of our model. A schema is how our app defines what the data looks like and also sets up the document in MongoDB. If that sounds confusing, it’ll make more sense once we see what’s going on.&lt;/p&gt;

&lt;p&gt;Let’s first start by creating a new folder called &lt;code&gt;models&lt;/code&gt;. Inside of this folder, let’s create a new file called &lt;code&gt;subscriber.js&lt;/code&gt;. Notice how we’re naming this file ‘subscriber’ singular as opposed to our routes file which is ‘subscribers’ plural. The idea is that the model will handle how each and every subscriber, on an individual level, will look inside of our database. The ‘subscribers’ routes handles sometimes multiple subscribers requests such as Get All Subscribers route. It’s an important thing to mention as verbiage is important when naming files in projects.&lt;/p&gt;

&lt;p&gt;In this new file, we want to first require Mongoose since we will be using their schema models:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mongoose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;mongoose&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;After we require mongoose, we’ll start by defining our schema&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Inside of this javascript object will be all of the keys for the different properties of our subscriber. These keys will include &lt;code&gt;name&lt;/code&gt;, &lt;code&gt;subscribedChannel&lt;/code&gt; and &lt;code&gt;subscribeDate&lt;/code&gt;. We essentially want to tell our database what to expect from each one of these key’s such as their type, if they’re required and if a default value should be applied.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mongoose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;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;subscriberSchema&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;mongoose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&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="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;subscribedChannel&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;subscribeDate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;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;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;now&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;type&lt;/code&gt; and &lt;code&gt;required&lt;/code&gt; properties should be pretty self explanatory. These are defining the expected schema type (a String and Date in this case) as well if that key is required upon entering information for a new subscriber.&lt;/p&gt;

&lt;p&gt;One thing to note about &lt;code&gt;subscribeDate&lt;/code&gt;, we set the type to Date instead of String since we will be expecting a date from the user. If no date is provided then we default it to the current date by using &lt;code&gt;Date.now&lt;/code&gt; .&lt;/p&gt;

&lt;p&gt;Moving on, the last line of code we want to write in our schema is the &lt;code&gt;module.exports&lt;/code&gt;. This will allow us to use and interact with the database using our schema. Mongoose has a special way of exporting models utilizing &lt;code&gt;mongoose.model()&lt;/code&gt; that takes two properties:&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;// exporting our subscriber schema&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;mongoose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Subscriber&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;subscriberSchema&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;‘Subscriber’ is the name we want to give the model in our database and then the next one is the schema that corresponds to that model which is our &lt;code&gt;subscriberSchema&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That’s it for our model! Let’s take a look at the finished schema to make sure we’ve got it all:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mongoose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;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;subscriberSchema&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;mongoose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&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="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;subscribedChannel&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;subscribeDate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;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;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;now&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="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;mongoose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Subscriber&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;subscriberSchema&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Routes – Create and Get Subscribers
&lt;/h2&gt;

&lt;p&gt;Now that we have our model setup with a schema for our database, let’s require it in our &lt;code&gt;subscribers.js&lt;/code&gt; route file below where we required &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="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="nf"&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;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;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&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;Subscriber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;../models/subscriber&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 we can pick up where we left off with our routes where we coded a shell for each one:&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;// Getting all subscribers&lt;/span&gt;
&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&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="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello World&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="c1"&gt;// Getting one subscriber&lt;/span&gt;
&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&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;/: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="p"&gt;})&lt;/span&gt;

&lt;span class="c1"&gt;// Creating one subscriber&lt;/span&gt;
&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&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="p"&gt;})&lt;/span&gt;

&lt;span class="c1"&gt;// Updating one subscriber&lt;/span&gt;
&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;patch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&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="p"&gt;})&lt;/span&gt;

&lt;span class="c1"&gt;// Deleting one subscriber&lt;/span&gt;
&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&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="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have our test response from earlier when we sent ‘Hello World’ to the server but we can go ahead and delete that since we want to actually tell that route to Get All Subscribers.&lt;/p&gt;

&lt;p&gt;The first thing we’ll need to do, after we get rid of our old &lt;code&gt;res.send('Hello World')&lt;/code&gt; line, is wrap the function in a promise with a try/catch statement:&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;// Get all subscribers&lt;/span&gt;

&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&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="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&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="p"&gt;{&lt;/span&gt;

  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside of our &lt;code&gt;try&lt;/code&gt; statement we want to get all of the subscribers from our model. So we want to set a new variable called subscribers to that model with a &lt;code&gt;.find()&lt;/code&gt; method applied to our Subscriber model.&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;// Get all subscribers&lt;/span&gt;

&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&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="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&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;subscribers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;Subscriber&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&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="p"&gt;{&lt;/span&gt;

  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As the name implies, the &lt;code&gt;find()&lt;/code&gt; Mongoose method works by returning all associated subscriber objects that meet its criteria. Since we’re returning all subscribers, we just leave the parentheses blank since we want all the subscribers:&lt;/p&gt;

&lt;p&gt;After that line we then want to send a response with the data of our &lt;code&gt;subscribers&lt;/code&gt; variable we just created in the form of JSON:&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;// Get all subscribers&lt;/span&gt;

&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&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="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&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;subscribers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;Subscriber&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&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="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;subscribers&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="p"&gt;{&lt;/span&gt;

  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, in our &lt;code&gt;catch&lt;/code&gt; statement we want to just catch any errors that may occur and have it sent to the user as a 500 error in JSON format:&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;// Get all subscribers&lt;/span&gt;

&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&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="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&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;subscribers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;Subscriber&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&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="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;subscribers&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="p"&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="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we have our route to send us all the subscribers in our database, we need to code a way for us to actually add a subscriber into our database. So, lets move onto our Create One Subscriber route so we can enter data about a subscriber:&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;// Create one subscriber&lt;/span&gt;

&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&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="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;subscriber&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;Subscriber&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="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="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;subscribedChannel&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;subscribedChannel&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;

  &lt;span class="k"&gt;try&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;newSubscriber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;subscriber&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&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="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;201&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newSubscriber&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="p"&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="nf"&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="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see its somewhat similar to our Get All Subscribers route except a few important differences. For one, we’re no longer doing a GET call on our database but a POST which will allow us to push data to our database.&lt;/p&gt;

&lt;p&gt;On this line:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const subscriber = new Subscriber({...&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;we are creating a variable that will be assigned to a new &lt;code&gt;Subscriber&lt;/code&gt; from our model that we created earlier. If you recall, we require a &lt;code&gt;name&lt;/code&gt;, &lt;code&gt;subscribedChannel&lt;/code&gt; and &lt;code&gt;subscribeDate&lt;/code&gt; properties for a new subscriber.&lt;/p&gt;

&lt;p&gt;These next two lines of code:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;name: req.body.name,&lt;br&gt;
 subscribedChannel: req.body.subscribedChannel&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We’re telling our route to save the request made from a user’s input of a new Subscriber &lt;code&gt;name&lt;/code&gt; property and &lt;code&gt;subscribedChannel&lt;/code&gt; property. Our &lt;code&gt;subscribeDate&lt;/code&gt; doesn’t need to be defined because it will default automatically to the date/time that this database entry is made.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;try&lt;/code&gt; and &lt;code&gt;catch&lt;/code&gt; statements should look familiar. We’re instead using a &lt;code&gt;.save()&lt;/code&gt; Mongoose method instead of &lt;code&gt;find()&lt;/code&gt; because this is how we will tell the database that we want it to hold the information a user passes to us through this router function.&lt;/p&gt;

&lt;p&gt;Lastly:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;...&lt;br&gt;
    res.status(201).json(newSubscriber)&lt;br&gt;
  } catch (err) {&lt;br&gt;
    res.status(400).json({ message: err.message })&lt;br&gt;
  }&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We’re sending the user a response with a &lt;a href="https://httpstatuses.com/201" rel="noopener noreferrer"&gt;success status of 201&lt;/a&gt; and to pass our new subscriber back to us as JSON. The catch is just like our Get All Subscribers route except we pass a &lt;a href="https://httpstatuses.com/400" rel="noopener noreferrer"&gt;400 error&lt;/a&gt; since this would be a user error for passing us bad data.&lt;/p&gt;
&lt;h2&gt;
  
  
  Let’s Create and Get Our First Subscriber!
&lt;/h2&gt;

&lt;p&gt;At this point we’ve created our Model and two Routes that will allow us to create a subscriber and then call that subscriber’s information from our database. Let’s switch gears back to our &lt;code&gt;route.rest&lt;/code&gt; file and create our first user:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET http://localhost:3000/subscribers

###

POST http://localhost:3000/subscribers
Content-Type: application/json

{
  "name": "Robert",
  "subscribedChannel": "Bennetts Channel"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With REST Client, we need to separate our different test requests with those three hashtags you see in between the two statements on line 3.&lt;/p&gt;

&lt;p&gt;Our first request should be the exact same as before so the only different one here is our new POST request that allows us to create a new subscriber with their name (Robert in my case) and the channel they subscribed to (&lt;a href="https://www.youtube.com/channel/UCDP-Mkz_lRoFSiP9_p1L3xQ" rel="noopener noreferrer"&gt;mine!&lt;/a&gt;). So lets run our POST request and see what we get:&lt;/p&gt;

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

&lt;p&gt;If everything went well, our response when we click ‘Send Request’ should look like the above. We can see that we received our 201 success status at the very top along with our Subscriber object at the bottom with all the information we just plugged in.&lt;/p&gt;

&lt;p&gt;Again, &lt;code&gt;subscribeDate&lt;/code&gt; is set automatically to the date of creation so we don’t need to manually set it. Now lets use our Get All Subscribers request and make sure that it returns us Robert’s information:&lt;/p&gt;

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

&lt;p&gt;Our response will look similar to our Create Subscriber response since we only have a single user in our database but if you create multiple subscribers then this will populate all of them for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Middle-what? The Middleware!
&lt;/h2&gt;

&lt;p&gt;We’re in the final stretch! The last things few things we need to do is complete our Delete, Update and Get One Subscriber routes and our REST API is complete!&lt;/p&gt;

&lt;p&gt;One thing in common that all 3 of the last routes share is getting the ID of a specific user. Instead of writing out that part of the code 3 times over we can just put that piece of code in its own function and call it as &lt;a href="https://mongoosejs.com/docs/middleware.html" rel="noopener noreferrer"&gt;middleware&lt;/a&gt; in the Mongoose GET/PATCH/POST statements. Lets place this middleware function called &lt;code&gt;getSubscriber&lt;/code&gt; right before our &lt;code&gt;module.exports = router&lt;/code&gt; line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getSubscriber&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="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;subscriber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;Subscriber&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&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="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;subscriber&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&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;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Cant find subscriber&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="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="p"&gt;){&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="p"&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;subscriber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;subscriber&lt;/span&gt;
  &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There’s a lot going on here so let’s break it down. The first line should look pretty familiar except that new property called &lt;code&gt;next&lt;/code&gt; . Basically, when &lt;code&gt;next&lt;/code&gt; is called its telling the function execution to move onto the next section of our code, which is the route function this &lt;code&gt;getSubscriber&lt;/code&gt; function will be added to.&lt;/p&gt;

&lt;p&gt;Our &lt;code&gt;try&lt;/code&gt; and &lt;code&gt;catch&lt;/code&gt; statements are opened up as with our other routes. We then define subscriber on line 3 equal to our Subscriber model object which we will then use the &lt;code&gt;findById&lt;/code&gt; method to find our subscriber that correlates to the ID the user passes in from the parent route. This will set the &lt;code&gt;subscriber&lt;/code&gt; to an object equal to that id.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Side Note:&lt;/em&gt; This part can be a little confusing but hang on until we get to the Update/Delete/Get One routes below. I’ll make more sense when we see it in action.&lt;/p&gt;

&lt;p&gt;Once we have &lt;code&gt;subscriber&lt;/code&gt; set to our model’s object, we check with an &lt;code&gt;if&lt;/code&gt; statement to see if that subscriber even exists with a &lt;code&gt;null&lt;/code&gt; check. If the subscriber is nonexistent then we want to throw a 404 error. Then our &lt;code&gt;catch&lt;/code&gt; is doing the familiar error check and sending the user back a 500 status code if that&lt;/p&gt;

&lt;p&gt;Finally we’re left with our last two lines of code from our middleware function:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;res.subscriber = subscriber&lt;br&gt;
next()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;res.subscriber&lt;/code&gt; is setting a variable on the response object which is equal to our subscriber object. This is useful so we don’t have to write that same line of code, we can just reference &lt;code&gt;res.subscriber&lt;/code&gt; from this function. Lastly, we use the &lt;code&gt;next()&lt;/code&gt; function after everything else is finished executing to tell the &lt;code&gt;getSubscriber&lt;/code&gt; function to move onto the actual request.&lt;/p&gt;

&lt;p&gt;Now that we’ve got our middleware function completed, let’s add it to our Delete, Update and Get One routes:&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;// Get one subscriber&lt;/span&gt;
&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&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;/:id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;getSubscriber&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="p"&gt;})&lt;/span&gt;

&lt;span class="c1"&gt;// Update one subscriber&lt;/span&gt;
&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;patch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/:id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;getSubscriber&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="c1"&gt;// Delete one subscriber&lt;/span&gt;
&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/:id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;getSubscriber&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Route – Get One Subscriber
&lt;/h2&gt;

&lt;p&gt;We did most of the heavy lifting for these last 3 routes with our middleware so horray for that. Let’s start off with our Get One 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="c1"&gt;// Get One Subscriber&lt;/span&gt;

&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&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;/:id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;getSubscriber&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="nf"&gt;json&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;subscriber&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;Look how ridiculously simple that looks. All we have to do is send the user a response in JSON with the &lt;code&gt;res.subscriber&lt;/code&gt; that we defined in our middleware function which returns that specific subscriber’s info. We can test this new route real quick to make sure our &lt;code&gt;getSubscriber&lt;/code&gt; middleware function and this new route we created actually works.&lt;/p&gt;

&lt;p&gt;Let’s hop back over to our &lt;code&gt;route.rest&lt;/code&gt; file and create a new subscriber with our Create Subscriber request so we can get that subscriber’s ID:&lt;/p&gt;

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

&lt;p&gt;Alright so we created a new subscriber and named him Bob and we can see he has a long ID associated with his object right above his name. I want to keep that ID so when we write our new GET route I can call Bob specifically by his ID. We can put this below our Get All Subscribers request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET http://localhost:3000/subscribers

###

GET http://localhost:3000/subscribers/5d3ce4ef1b5de0b79d3443b9

###

POST http://localhost:3000/subscribers
Content-Type: application/json

{
  "name": "bob",
  "subscribedChannel": "Bennetts Channel"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On line 5 is where we’ll create the new test request, so put in your newly created user’s ID (yours will be different than mine above) and click ‘Send Request’:&lt;/p&gt;

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

&lt;p&gt;If everything went well, we shouldn’t see a change on our response to the right because we’re just calling the same user that we just created. Give yourself a pat on the back, your middleware function and Get One route works!&lt;/p&gt;

&lt;h2&gt;
  
  
  Route – Delete Subscriber
&lt;/h2&gt;

&lt;p&gt;Now that we know our middleware is doing its job, lets switch back on over to our &lt;code&gt;subscribers.js&lt;/code&gt; routes file and finish our last two routes starting with Delete:&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;// Delete one subscriber&lt;/span&gt;

&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/:id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;getSubscriber&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&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;subscriber&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;remove&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="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Deleted This Subscriber&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="p"&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="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We open up our &lt;code&gt;try&lt;/code&gt; statement and then we plug in our &lt;code&gt;await&lt;/code&gt; operator right before we set our &lt;code&gt;res.subscriber&lt;/code&gt; to then use the &lt;code&gt;remove()&lt;/code&gt; method to delete the subscriber that the &lt;code&gt;res.subscriber&lt;/code&gt; object was set to. We then want to tell the user that we successfully deleted the subscriber by passing the response message in JSON:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;res.json({ message: 'Deleted This Subscriber' })&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;As always, we want our &lt;code&gt;catch&lt;/code&gt; to send the user the appropriate error if one did occur. That’s it for delete!&lt;/p&gt;

&lt;h2&gt;
  
  
  Route – Update Subscriber
&lt;/h2&gt;

&lt;p&gt;Our Update Subscriber route is the very last thing we need to write for this application to be fully functional! Ok so before we get into the code lets get a general idea of how updating will work in this case:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User updates just the name&lt;/li&gt;
&lt;li&gt;User updates just the channel&lt;/li&gt;
&lt;li&gt;User updates both name and channel&lt;/li&gt;
&lt;li&gt;Or they mess up and it throws an error&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Our requirements need for us to essentially check and see if any changes were made and if so, update them appropriately. Now onto the code:&lt;br&gt;
&lt;/p&gt;

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

&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;patch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/:id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;getSubscriber&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &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;name&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&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;subscriber&lt;/span&gt;&lt;span class="p"&gt;.&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="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;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;subscribedChannel&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&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;subscriber&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;subscribedChannel&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;subscribedChannel&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;try&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;updatedSubscriber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;subscriber&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&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="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;updatedSubscriber&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;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&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="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We start our function off with a PATCH method, which we discussed when initially defining the shell of our routes. Now you can see we’ve added two &lt;code&gt;if&lt;/code&gt; statements to our function. The first if statement is checking to see if the name coming from the &lt;code&gt;body&lt;/code&gt; of the user’s request is not equal to &lt;code&gt;null&lt;/code&gt;. This is an important check because if it is equal to &lt;code&gt;null&lt;/code&gt; then that means the user did not pass any data about name through our route function. If they did then we move onto this line:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;res.subscriber.name = req.body.name&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Where we’re setting our subscriber’s name from &lt;code&gt;res.subscriber&lt;/code&gt; and setting the name now equal to the new name that the user passed in from their request.&lt;/p&gt;

&lt;p&gt;The same logic follows here:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;res.subscriber.subscribedChannel = req.body.subscribedChannel&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Where we’re checking to see if the user updated the &lt;code&gt;subscribedChannel&lt;/code&gt; and if so, we then perform the same sequence of changing the current &lt;code&gt;subscribedChannel&lt;/code&gt; to the new one from the user’s request.&lt;/p&gt;

&lt;p&gt;After we’ve made these &lt;code&gt;if&lt;/code&gt; statement checks we then want to tell the function to then save these new changes into our database. This is easily done within our &lt;code&gt;try&lt;/code&gt; statement where we take the &lt;code&gt;res.subscriber&lt;/code&gt; object with our new name and/or channel and then add the &lt;code&gt;save()&lt;/code&gt; method onto it within a new variable called &lt;code&gt;updatedSubscriber&lt;/code&gt;. We then want to pass this new &lt;code&gt;updatedSubscriber&lt;/code&gt; object to our user in the form of JSON:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;try {&lt;br&gt;
    const updatedSubscriber = await res.subscriber.save()&lt;br&gt;
    res.json(updatedSubscriber)&lt;br&gt;
   }&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;That’s literally everything we need in our &lt;code&gt;subscribers.js&lt;/code&gt; route file so let’s take a pause here and make sure we’ve got everything up to this point. Go to my &lt;a href="https://github.com/Beznet/node-api" rel="noopener noreferrer"&gt;github repo&lt;/a&gt; for this project and make sure your code accurately mirrors what I have before moving onto the final tests below.&lt;/p&gt;
&lt;h2&gt;
  
  
  The Final Test
&lt;/h2&gt;

&lt;p&gt;We’ve completed our last two routes, let’s go into our &lt;code&gt;route.rest&lt;/code&gt; file and test these bad boys out and make sure they work correctly.&lt;/p&gt;

&lt;p&gt;Our Delete request is just as simple as our Get One Subscriber route except instead of using the GET request we’re naturally going to use the DELETE request instead. So get the ID of one of the subscribers in your database and let’s create that test route:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;###

DELETE http://localhost:3000/subscribers/5d3e0db7cb4be0bfc4c25ff9
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let’s click ‘Send Request’ and see if our user is successfully deleted:&lt;/p&gt;

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

&lt;p&gt;Nice! So we can see we got a message of ‘Deleted This Subscriber’ on the right hand side which means we were successful. Now if you take that same ID that you just deleted and try to request it using our Get One Subscriber request, it should tell us that it cannot find that subscriber since they no longer exist in our database:&lt;/p&gt;

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

&lt;p&gt;Our last request will be to update an existing subscriber’s information in our database with our Update route. Since we just deleted our last subscriber, go ahead and create a new subscriber and lets write our Update request using PATCH:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;###

PATCH http://localhost:3000/subscribers/5d3e144ecb4be0bfc4c25ffa
Content-Type: application/json 

{
  "name": "Tommy"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I just created a new subscriber before running the above PATCH request and named them Lizzy:&lt;/p&gt;

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

&lt;p&gt;Alright so if we run the above PATCH request we should see Lizzy’s name change to Tommy:&lt;/p&gt;

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

&lt;p&gt;If everything went smoothly then we just were able to successfully update Lizzy’s name to Tommy.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Guys, we made it. I really hope this tutorial was helpful to some of you. We went over a lot of stuff so if you’re feeling overwhelmed then thats totally understandable. But realize we just made a pretty awesome backend piece of code that translates into so many different real-world applications. So big props to you for making it through it all!&lt;/p&gt;

&lt;p&gt;If you ever got stuck or found something worth mentioning, go ahead and leave me a comment below. Also feel free to follow me on &lt;a href="https://twitter.com/beznet" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; and &lt;a href="https://www.youtube.com/channel/UCDP-Mkz_lRoFSiP9_p1L3xQ" rel="noopener noreferrer"&gt;Youtube&lt;/a&gt; as I post regularly on both. Happy coding everyone!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published &lt;a href="https://www.bennettdungan.com/2019/07/29/build-a-rest-api-with-node-express-mongodb/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>rest</category>
      <category>api</category>
      <category>express</category>
    </item>
    <item>
      <title>At work, do you have planned roundups with coworkers to discuss new and/or unfamiliar coding concepts?</title>
      <dc:creator>Bennett Dungan</dc:creator>
      <pubDate>Thu, 06 Jun 2019 02:18:45 +0000</pubDate>
      <link>https://dev.to/beznet/at-work-do-you-have-planned-roundups-with-coworkers-to-discuss-new-and-or-unfamiliar-coding-concepts-145k</link>
      <guid>https://dev.to/beznet/at-work-do-you-have-planned-roundups-with-coworkers-to-discuss-new-and-or-unfamiliar-coding-concepts-145k</guid>
      <description>&lt;p&gt;Im newer at my place of work and the skill gap is fairly large between myself and my coworkers. I was thinking of having a weekly 'roundup' of sorts where either I or someone else has a concept on the agenda to discuss. For instance, I just discovered what 'currying' is in Javascript and would love to discuss it with the others and see if there are ways we can implement it into our projects. &lt;/p&gt;

&lt;p&gt;Does anyone else have these sorts of meetups with their coworkers to get on the same page knowledge-wise? If so, how are they typically structured? &lt;/p&gt;

</description>
      <category>discuss</category>
      <category>career</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Create a Horizontal Mobile Scroll Box Using CSS Flexbox and Media Query</title>
      <dc:creator>Bennett Dungan</dc:creator>
      <pubDate>Mon, 13 May 2019 03:30:48 +0000</pubDate>
      <link>https://dev.to/beznet/create-a-horizontal-mobile-scroll-box-using-css-flexbox-and-media-query-1h5d</link>
      <guid>https://dev.to/beznet/create-a-horizontal-mobile-scroll-box-using-css-flexbox-and-media-query-1h5d</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published &lt;a href="https://www.bennettdungan.com/2019/05/12/create-a-horizontal-mobile-scroll-box-using-css-flexbox-and-media-query/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I had the chance to flex my CSS chops recently, which turned out to be pretty weak, but I learned a few cool things along the way. I was tasked to create a vertical list that transforms to horizontal scrolling when sized down to mobile. This was the outcome:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.bennettdungan.com%2Fwp-content%2Fuploads%2F2019%2F05%2FMay-12-2019-00-29-15.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.bennettdungan.com%2Fwp-content%2Fuploads%2F2019%2F05%2FMay-12-2019-00-29-15.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The two main takeaways from this came from using CSS's media queries and flexbox. I had only done some real quick and dirty CSS styling in the past so this was my first exposure to both of these two tools. I whipped up this &lt;a href="https://codepen.io/Beznet/pen/vwOPRa" rel="noopener noreferrer"&gt;simple Codepen version&lt;/a&gt; of the above where you can see the vertical to horizontal list and scroll in action. The majority of the magic comes from this little chunk of CSS:&lt;/p&gt;

&lt;pre class="wp-block-syntaxhighlighter-code"&gt;&lt;a class="mentioned-user" href="https://dev.to/media"&gt;@media&lt;/a&gt; (max-width: 992px) {
  .container {
      display: flex;
      flex-wrap: nowrap;
      height: 300px;
      overflow-x: auto;
      width: auto;
  }
}&lt;/pre&gt;

&lt;p&gt;The first thing you'll notice is that &lt;code&gt;@media&lt;/code&gt; rule  which is how Im telling the div with all the items to apply the subsequent CSS properties to the &lt;code&gt;.container&lt;/code&gt; class.  To put it simply, when the screen size hits 992px or lower, the &lt;code&gt;.container&lt;/code&gt; class now changes/adds the listed properties starting with &lt;code&gt;display: flex&lt;/code&gt; .&lt;/p&gt;

&lt;p&gt;Next, we're adding flexbox with &lt;code&gt;display: flex&lt;/code&gt; and then making sure that the items do not wrap within the container as we scale it down with &lt;code&gt;flex-wrap: nowrap&lt;/code&gt; . I changed the height of the container to a more narrow 300px so it creates a mobile-friendly view of the item that scroll. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Sidenote: If you're unfamiliar with Flexbox , I highly recommend doing this interactive learning game: &lt;/em&gt;&lt;a href="https://flexboxfroggy.com/" rel="noopener noreferrer"&gt;&lt;em&gt;Flexbox Froggy&lt;/em&gt;&lt;/a&gt;&lt;em&gt; . It teaches you most of the basic and some advanced properties of Flexbox by maneuvering a frog onto its lillypad. &lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Finally we add &lt;code&gt;overflow-x: auto&lt;/code&gt; to allow the items within the container to have scrollable functionality on the X axis when the items spill outside of the parent container. Without this property we'd have something that looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.bennettdungan.com%2Fwp-content%2Fuploads%2F2019%2F05%2FScreen-Shot-2019-05-12-at-11.59.11-AM-1024x523.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.bennettdungan.com%2Fwp-content%2Fuploads%2F2019%2F05%2FScreen-Shot-2019-05-12-at-11.59.11-AM-1024x523.png" alt=""&gt;&lt;/a&gt;:(&lt;/p&gt;

&lt;p&gt;Once we have all those properties put together, we're left with a nifty little item list that transforms to mobile-friendly horizontal scrolling:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.bennettdungan.com%2Fwp-content%2Fuploads%2F2019%2F05%2FMay-12-2019-12-27-55.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.bennettdungan.com%2Fwp-content%2Fuploads%2F2019%2F05%2FMay-12-2019-12-27-55.gif" alt="codepen scroll animation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Typically, you're going to be taking a list of items that is horizontal in desktop screen sizes and then scaling it down to a vertical list when hitting mobile screens. So we're essentially forcing the opposite to happen here which isn't too common and why its sometimes hard to find a solution for it on places like Stackoverflow. &lt;/p&gt;

&lt;p&gt;Hopefully you found this useful. If you know of a better way or some clever little tricks I missed please be sure to let me know! &lt;/p&gt;

</description>
      <category>css</category>
      <category>flexbox</category>
      <category>mediaquery</category>
      <category>webdesign</category>
    </item>
    <item>
      <title>Life Update: I’m Officially a Developer</title>
      <dc:creator>Bennett Dungan</dc:creator>
      <pubDate>Mon, 10 Dec 2018 01:55:53 +0000</pubDate>
      <link>https://dev.to/beznet/life-update-im-officially-a-developer-50bj</link>
      <guid>https://dev.to/beznet/life-update-im-officially-a-developer-50bj</guid>
      <description>&lt;p&gt;It’s been awhile. I promise my absence has been for good reason though, not because I fell off the coding wagon. Actually, quite the opposite. As the title says, I got a freakin’ job as a web application developer! I was hired on back in September and have been there for about 3 months now. Since then coding has been apart of my daily life more than ever before so my blog updates have sort of taken a back seat. &lt;/p&gt;

&lt;p&gt;I do apologize about the long hiatus though. From the interviewing process (which was quite brutal for someone of my novice skill level) to the job itself , life has been super draining. Don’t get me wrong, I’m learning loads of stuff each and every day but I now know this is where the real journey starts. Getting the job was just the beginning.&lt;/p&gt;

&lt;p&gt;I definitely intend to give a full recap about the interview, personal struggles, how I overcame certain obstacles and ultimately landed the job but in the mean time I wanted to let everyone know that I’m alive and doing well. Until next time, happy coding!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published &lt;a href="https://www.bennettdungan.com/2018/12/10/life-update-im-officially-a-developer/"&gt;on my blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>career</category>
      <category>lifeupdate</category>
    </item>
    <item>
      <title>Learning Code While Working a Full Time Job</title>
      <dc:creator>Bennett Dungan</dc:creator>
      <pubDate>Fri, 10 Aug 2018 02:51:58 +0000</pubDate>
      <link>https://dev.to/beznet/learning-code-while-working-a-full-time-job-365p</link>
      <guid>https://dev.to/beznet/learning-code-while-working-a-full-time-job-365p</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published &lt;a href="https://www.bennettdungan.com/2018/08/10/learning-code-while-working-a-full-time-job/"&gt;here&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This is about my journey of learning how to code while also maintaining typical 8 to 5. Spoiler, its hard as hell and the burn-out is super easy. Though I'm here to hopefully shed some light on what's worked for me and how I maintain my sanity...&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;b&gt;1. Make coding your hobby&lt;/b&gt;
&lt;/h3&gt;

&lt;p&gt;I've talked a bit about this in my previous posts but I think it's worth reiterating. I haven't had success in the past attempting to balance work, social activities, hobbies and learning code. There's just not enough time in the day to do everything I wanted so I had to prioritize. I used to come home after work and get online with friends to play games. As hard as it was, I've had to cut that out of my life temporarily. Anyone who's ever played online games knows that its a sinkhole for time. One moment you've promised to just play one 20 min game of Overwatch and the next thing you know it 3 hours have passed by. So it was imperative that I put a halt to this if I wanted to progress in any sort of fashion. I've also been cooking less than I used to. That's something I didn't want to see diminish but cooking can take me a whole evening of preparation, so I usually just opt for the simple sandwich or omelet lately (my girlfriend is upset by this side-effect). The point is, if the majority of your day is taken up by your day job then you're going to need to make major sacrifices. Its just the nature of the beast but a necessary step if you're wanting to progress.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Update:&lt;/em&gt; Just to clarify, I'm not suggesting to totally rid yourself of everything that makes you happy. My suggestion is to take a hard look at what you're doing before/after work and ask yourself "Is this worth my time? Can I utilize this time to learn code?". Assuming you're learning code to one day land a dev position, this is something I've found to work the best for me. Adjust your time constraints on leisure activities according to what fits your life balance.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;b&gt;2. Have a long-term outlook&lt;/b&gt;
&lt;/h3&gt;

&lt;p&gt;This isn't going to come to you overnight. With the influx of these coding 'bootcamps' that promise to get you job ready in 3-6 months, the realistic expectation for people has been massively skewed. This is a bit like weight training, your muscles can only strengthen so much in a given period of time. If you're bench-pressing 95lbs today and some guy promises to train you up to 225lbs in 6 months, it's just not physically possible for most people to achieve this. Your brain is like a muscle, you can only train it to absorb so much in a given day before you just burn out. So I've adopted the slow and steady approach. I don't cram 5-6 hours of coding in after work because that is a recipe for disaster. In fact, I recently spent the weekend trying to cram as much coding as I could in to get this weather app built and quite frankly, I was miserable afterward. I find an hour or two of coding each and every day to be much healthier than just doing these cram sessions. Plus it gives your mind time to process what you've learned in much more manageable chunks. If you haven't been to my &lt;a href="https://www.bennettdungan.com/coding_log/"&gt;Daily Coding Log &lt;/a&gt; then you might not have seen this quote:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;“Continuous improvement is better than delayed perfection.” – Mark Twain&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Just keep at it each and every day no matter how little you do or learn. Just keep chugging.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;b&gt;3. Start a Coding Log&lt;/b&gt;
&lt;/h3&gt;

&lt;p&gt;With the long-term approach, it's sometimes hard to remember where you started and just how much you've progressed. Even though I've only had my coding log for a few months, I have gone back a few times and looked at my notes on Git and Javascript basics and it makes me feel really good to know how far I've come. I've also named it "Daily Coding Log" for a reason, so I commit to myself to code daily. It basically doubles as an accountability tool when there's no one else there to make sure you're keeping up. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;b&gt;4. Code in the mornings before work&lt;/b&gt;
&lt;/h3&gt;

&lt;p&gt;This was probably the hardest one for me to adapt to because I have always been a night owl. I started off coding after work but found my attention span to be much less and often found myself getting distracted often since I was usually at home. I just didn't have the energy after work because I'm mentally exhausted by the evening so pushing more information into my head just didn't pan out. One day I forced myself out of bed at 6am and got to work just before 7am so I could get 1 hour of coding in before 8am rolled around. Turns out, my head was much clearer without the clutter of the day fogging up my mind and I was able to focus a lot easier (this could also be because of the coffee). This is now my go-to time of day for coding since the distractions are minimal and I'm able to start the day coding with a clear mind. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;b&gt;5. Make friends with smart people&lt;/b&gt;
&lt;/h3&gt;

&lt;p&gt;This one might sound kind of weird to you, you might be thinking "what do my friends have to do with this?". There have been a bunch of times where I've hit a brick wall and there wasn't a single Stack Overflow document on the entire web that could have helped me. This is where having a friend whose very well versed in programming comes in. I'm very lucky to be friends with multiple programmers all of whom are very good at what they do. I've reached out to a few of them on occasion when I was losing all hope and just getting 10-30minutes of their time can be immensely helpful. Having someone right there to show you the process and how to go about doing even the littlest of things has been one of the most helpful learning resources for me in my coding journey. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;b&gt;6. Go to local coding meetups&lt;/b&gt;
&lt;/h3&gt;

&lt;p&gt;So you just read tip #5 and are thinking, "Wow cool Bennett, you've got smarty pants friends, great freakin' job. But I don't know anyone who programs. What do I do?". Well, you could go online and ask random internet people for help, which is useful OR you can go to your local coding group's meetups. This place is great for getting to know other local programmers and networking for when you're job-ready. Having trouble finding a coding meetup?&lt;/p&gt;

&lt;p&gt;Try here: &lt;a href="//www.meetup.com/topics/computer-programming/"&gt;www.meetup.com/topics/computer-programming/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If that doesn't work then do a little searching around on Facebook. My local coding group, &lt;a href="https://www.facebook.com/groups/acadianasoftwaregroup/"&gt;Acadiana Software Group&lt;/a&gt;, isn't on meetup.com but they have a Facebook page so give that a shot. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;b&gt;Conclusion&lt;/b&gt;
&lt;/h3&gt;

&lt;p&gt;Those are my 6 tips for all my fellow aspiring developers who are struggling with the 8-5 grind. These tips are just what have worked for me so if you're stuck in a rut, give them a try and let me know how they worked. If you have any of your own tips you'd like to share, please leave me a comment! Happy coding.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>tips</category>
    </item>
    <item>
      <title>Building My First App with Limited Coding Knowledge</title>
      <dc:creator>Bennett Dungan</dc:creator>
      <pubDate>Sun, 24 Jun 2018 17:20:58 +0000</pubDate>
      <link>https://dev.to/beznet/building-my-first-app-with-limited-coding-knowledge-1p9j</link>
      <guid>https://dev.to/beznet/building-my-first-app-with-limited-coding-knowledge-1p9j</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally Published &lt;a href="https://www.bennettdungan.com/2018/06/23/building-my-first-app-the-process/" rel="noopener noreferrer"&gt;Here&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fhbwiwjji3huy3669bon4.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fhbwiwjji3huy3669bon4.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h6&gt;
  
  
  &lt;em&gt;image source - weeblytutorials.com&lt;/em&gt;
&lt;/h6&gt;

&lt;p&gt;A ton of beginners believe that they need to learn an immense amount of code before they can ever build anything useful. I've felt like that before, hell I still get that feeling of extreme self-doubt but its less frequent than before. I'm here to prove you CAN build an app that serves a purpose with very limited programming knowledge. There's a few prerequisites that you must have that are not even coding related before you decide to build just anything. I'll list the ones I find most important:&lt;/p&gt;


&lt;li&gt;&lt;b&gt;Do you really want to solve problems and build things that make a difference for people?&lt;/b&gt;&lt;/li&gt;
&lt;br&gt;
&lt;li&gt;&lt;b&gt;Can you identify a need or want that you have a desire to solve?&lt;/b&gt;&lt;/li&gt;
&lt;br&gt;
&lt;li&gt;&lt;b&gt;Are you willing to put aside leisure activities to solve this problem?&lt;/b&gt;&lt;/li&gt;

&lt;p&gt;I find the most successful programmers are not the people with the best coding skills, its the people who want to genuinely make a difference.  If you're still struggling with those aspects then you maybe need to re-look at the whole reason you are in this game.&lt;/p&gt;

&lt;p&gt;Ok so if you've got those 3 questions above answered, then we can move on. Just as a little background, I currently work at a marketing agency and we use a program called Google Adwords to setup and deploy advertisements. Without getting into too much boring details, we use these things called 'keywords' to basically figure out who we want to show the ads to when people search for things on Google. There's a few modifications we can make to these keywords to alter their properties. For example, I can take the word "find a plumber" and change its properties in 3 different ways, like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;+find a +plumber&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"find a plumber"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;[find a plumber]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I used to manually adjust these keywords one by one so it took a stupid amount of time to complete. I knew there had to be a better way, so I searched around and found this cool website called &lt;a href="http://keywordstoaster.worldofsolomon.com/" rel="noopener noreferrer"&gt;Keyword Toaster&lt;/a&gt;. This was great because I could now save a ton of time by just copying/pasting my chunk of keywords here and have this website convert them for me. Though, there were a few problems I identified that I feel could be improved:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Prepositions shouldn't be include for modified broad keywords&lt;/li&gt;
&lt;li&gt;I had rather edit the keywords in the same window as Adwords&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So it dawned on me, what if I just made a Chrome Extension that fulfilled these needs? All the app is essentially doing is taking a string, altering it, then returning the altered string in an output box. Easy right? Well, kinda...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F4rs1b14cpq6k055c2a8k.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F4rs1b14cpq6k055c2a8k.jpg"&gt;&lt;/a&gt; I looked into what it takes to create a Chrome Extension and found that I should primarily be using Javascript. One thing that made me go with a Chrome Extension is A) I could use the extension in the same window as Adwords and B) No backend/server-side coding needed. I rarely see anyone suggest creating a Chrome Extension to newbies but this was the easiest, most straightforward platform to launch my simple app to the world.&lt;/p&gt;

&lt;p&gt;Alright so, I had a minimal amount of JS knowledge beforehand but I knew I really needed to brush up on the basics. So I went through a highly recommended course on &lt;a href="https://watchandcode.com/" rel="noopener noreferrer"&gt;watchandcode.com&lt;/a&gt; that taught me these essential concepts:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. How to read Javascript&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;2. How to debug&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;3. Functions/Arrays&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;4. Basic DOM manipulation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The course basically teaches you how to create a simple Todo app in your browser. This is perfect because all a Todo app does is take an input and display an output. If you think about it, that's almost the core function of most applications at a very basic level. So what I did was run through the whole course once, then a second time. During the second pass of the course, I essentially took what was being taught and applied it to the concept of the app I was trying to create. I was able to take 80% of the code taught and use it in creating my app. The only real difference in this case was altering the output, which I accomplished with a little REGEX.&lt;/p&gt;

&lt;p&gt;To live test the code I was writing I used glitch.com. This made it super easy to see my changes in real time for an app of this size. I wasn't overly worried about CSS so it looked pretty fugly but all I cared about was the core functionality. Trust me, I make it sound like this was a simple process but even though most of the code I used was from the Watch and Code lesson, I had to reach out to people on different Slack channels and refer to Stack Overflow countless times for help.&lt;/p&gt;

&lt;p&gt;After many months, my first little application, Keyword Modifier, was born on the Chrome Web Store!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzlgq2evuox6ek0lqq13e.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzlgq2evuox6ek0lqq13e.jpg"&gt;&lt;/a&gt;&lt;br&gt;
Here is a link to the first version I had initially launched.: &lt;a href="https://github.com/Beznet/keyword-mod" rel="noopener noreferrer"&gt;https://github.com/Beznet/keyword-mod&lt;/a&gt; . &lt;br&gt;
Its a little cleaner now after some refactoring and added functionality, so you will see some minor changes to it &lt;a href="https://chrome.google.com/webstore/detail/keyword-modifier/dhpaponoajbgfahgmcbchndpjbooapog?hl=en" rel="noopener noreferrer"&gt;if you download it today&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The point of this whole article is to prove that if you have the desire to create and build, its going to carry you through the hurdles of coding regardless of how little you know.&lt;/p&gt;

&lt;p&gt;If you're reading this and currently struggling with your idea for an app, leave me a comment! I'd be happy to talk about your process and help you along.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>chromeextension</category>
      <category>beginners</category>
      <category>tips</category>
    </item>
  </channel>
</rss>
