<?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>Forem: Kyle Petersen</title>
    <description>The latest articles on Forem by Kyle Petersen (@kpete2017).</description>
    <link>https://forem.com/kpete2017</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%2F455373%2F1ae57b24-d574-43d7-9d50-e9860348d146.jpeg</url>
      <title>Forem: Kyle Petersen</title>
      <link>https://forem.com/kpete2017</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/kpete2017"/>
    <language>en</language>
    <item>
      <title>A QuickStart Guide For TypeScript</title>
      <dc:creator>Kyle Petersen</dc:creator>
      <pubDate>Sun, 29 Nov 2020 22:17:41 +0000</pubDate>
      <link>https://forem.com/kpete2017/a-boot-campers-guide-to-typescript-2h36</link>
      <guid>https://forem.com/kpete2017/a-boot-campers-guide-to-typescript-2h36</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;TypeScript is a strongly typed programming language developed by Microsoft and released in 2012. The language was created in order to address the criticisms of working with JavaScript mainly addressing how it is dynamically typed. Since JavaScript is interpreted within the browser's compiler and not at the time of writing the code, if a mistake is made, it will not be caught until the browser compiles the code and shoots back an error. TypeScript fixes this by running the code through its own compiler and adding strict 'types' to your programming meaning you can catch mistakes quickly and easily before production. The best part is since TypeScript is a superset of JavaScript, it has virtually no learning curve for a JavaScript developer.&lt;/p&gt;

&lt;h1&gt;
  
  
  Installation
&lt;/h1&gt;

&lt;p&gt;In order to install TypeScript, you are going to need Node js. To Install Node, navigate to &lt;a href="https://nodejs.org/en/download/"&gt;here&lt;/a&gt; follow the instructions for your appropriate operating system.&lt;/p&gt;

&lt;p&gt;After Node is installed, you can install TypeScript by running the command &lt;code&gt;npm install typescript --save-dev&lt;/code&gt; within your terminal.&lt;/p&gt;

&lt;h1&gt;
  
  
  Basic Use
&lt;/h1&gt;

&lt;p&gt;We can create a new TypeScript file by adding &lt;code&gt;.ts&lt;/code&gt; to the end of any of our file names. For example, if we wanted to create a new file named "Practice" we can just run the command &lt;code&gt;touch practice.ts&lt;/code&gt;. With this created, we can go ahead and start writing our TypeScript code within the file.&lt;/p&gt;

&lt;p&gt;Since TypeScript is a superset of JavaScript you can get away with just typing plain JavaScript within your .ts file and it will still compile perfectly fine. So to test this, we can go ahead and write the code this code on our first line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log("TypeScript Practice");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that the code is written, we can run this code by using the command tsc ("TypeScript Compiler") followed by our filename. So if we go ahead and run &lt;code&gt;tsc practice.ts&lt;/code&gt; from within our terminal you should see a new file named "practice.js" pop up. This is our TypeScript which has been run through our compiler and translated into JavaScript. Notice since we have used basic JavaScipt within our .ts file that nothing has changed.&lt;/p&gt;

&lt;h1&gt;
  
  
  Types
&lt;/h1&gt;

&lt;p&gt;Now we can get into one of the main reasons to get into TypeScript is it's enabling of static typing. One reason it achieves is by assigning each variable you create its only strong "Type". You can assign the type of each variable by adding a colon during the variable declaration following whatever primitive you wish to assign it. For example, if I wanted to assign an age to the type of number and set its value equal to 25, I can write the code &lt;code&gt;let age: number = 25;&lt;/code&gt;. Now, if further down the line I try to assign the variable age to anything besides a number such as &lt;code&gt;age = "Twenty Five";&lt;/code&gt;, the compiler throws an error allowing us to fix the issue immediately while knowing its exact position if we use a compatible text editor such as VSCode.&lt;/p&gt;

&lt;h1&gt;
  
  
  TS Config
&lt;/h1&gt;

&lt;p&gt;TypeScript has a huge array of options you can mess with in order to change the language and compliers behavior. For example, within our practice.ts file lets create an async function like so.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function practice() {

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

&lt;/div&gt;



&lt;p&gt;Now if we run &lt;code&gt;tsc practice.ts&lt;/code&gt; and navigate over to our practice.js file, we can see that the JavaScript looks quite a bit messy compared to what we're used to for an async function. This is because typescript is built to be used with multiple different versions of Javascript and currently defaults to ES5. This behavior can be changed by adding a tsconfig.json file. Go ahead and run &lt;code&gt;touch tsconfig.json&lt;/code&gt; within your terminal and open the newly created file within your text editor. From here we are going to add this code in order to default or compilers behavior to the latest version of JavaScript. Now if we run &lt;code&gt;tsc&lt;/code&gt; within our terminal we should see our practice.js file should look much cleaner now that we are using the latest version of JavaScript by default.&lt;/p&gt;

&lt;h1&gt;
  
  
  Interfaces
&lt;/h1&gt;

&lt;p&gt;One last awesome tool I would like to talk about when it comes to TypeScript is the interface. When creating a new JavaScript object, we can create something called an interface meaning we can give Types to all of our object's values. For example, I could create an interface to a new object we are creating called Sandwich by typing out this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface Sandwich {
  meatType: string;
  numberOfCondiments: number;
  breadType: string;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can create a new object and assign it to the interface of Sandwich which will allow all of our variables to have a strong Type. So if we were to code the following below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let newSandwich: Sandwich = {
  meat: "Turkey",
  numberOfCondiments: "2",
  breadType: "Wheat"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We would be warned that our numberOfCondiments value contains the wrong type and should be changed to avoid an error.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to Become a Bootcamp Level Web Developer</title>
      <dc:creator>Kyle Petersen</dc:creator>
      <pubDate>Mon, 23 Nov 2020 06:45:34 +0000</pubDate>
      <link>https://forem.com/kpete2017/how-to-become-a-bootcamp-level-web-developer-37f3</link>
      <guid>https://forem.com/kpete2017/how-to-become-a-bootcamp-level-web-developer-37f3</guid>
      <description>&lt;p&gt;Coding Bootcamps are some of the fastest ways to become a web developer with many programs taking just 15 weeks you are considered job-ready. Although it can require you to learn an extremely dense amount of information within an extremely short amount of time the Bootcamp curriculum is definitely a good one to learn if you want to get into web development professionally. Here are the technologies and resources you will want to learn if you want to become a Bootcamp Level web developer.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Backend
&lt;/h2&gt;

&lt;p&gt;Many web applications have what is called a 'frontend' meaning the website with which is run within the web browser as well as a 'backend' which is run externally within a separate server. The backend can be written in pretty much any language but there are definitely some more preferred ones. Most Bootcamps tend to sway towards Ruby on Rails as the technology of choice for the backend.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ruby
&lt;/h3&gt;

&lt;p&gt;In order to learn Ruby on Rails, you should definitely be picking up the Ruby programming language first. Developed in the mid-1990s, Ruby is a 'developers first' language created by Yukihiro "Matz" Matsumoto in Japan. Ruby is dynamically typed as well as uses its own garbage collection making the language a joy to type in as well as making it extremely friendly for new developers. Some amazing resources I have found in learning Ruby is FreeCodeCamp's Ruby programming language full course which you can find &lt;a href="https://www.youtube.com/watch?v=t_ispmWmdjY"&gt;here&lt;/a&gt; on YouTube as well as Boris Paskhaver's course on Udemy you can find &lt;a href="https://www.udemy.com/course/learn-to-code-with-ruby-lang/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ruby On Rails
&lt;/h3&gt;

&lt;p&gt;Once you have gained a bit of experience in using Ruby it is now time to move on to Ruby on Rails. Ruby on Rails is a backend serverside application that uses an MVC architecture and has a ton of different uses. Although out of Bootcamp, you are mainly going to be using Rails in order to create something called an API for your frontend to use. Team Tree House has an amazing guide on Rails which can be found &lt;a href="https://teamtreehouse.com/tracks/rails-development?campaign=%2A%2ALP+-+NonTM+-+Track+-+Ruby&amp;amp;content=448954904817&amp;amp;keyword=learn%20ruby%20on%20rails&amp;amp;cid=10232&amp;amp;utm_term=learn%20ruby%20on%20rails&amp;amp;utm_campaign=%2A%2ALP+-+NonTM+-+Track+-+Ruby&amp;amp;utm_source=google&amp;amp;utm_medium=cpc&amp;amp;hsa_acc=9235032315&amp;amp;hsa_cam=10568350754&amp;amp;hsa_grp=108034944121&amp;amp;hsa_ad=448954904817&amp;amp;hsa_src=g&amp;amp;hsa_tgt=aud-763483373166:kwd-335935963144&amp;amp;hsa_kw=learn%20ruby%20on%20rails&amp;amp;hsa_mt=e&amp;amp;hsa_net=adwords&amp;amp;hsa_ver=3&amp;amp;gclid=CjwKCAiAtej9BRAvEiwA0UAWXs9jYHAPKYSQMxaEbCy5aSvlQ0JtHce5VpBpIz9t4ZdFVC-1UdGVDBoCG4QQAvD_BwE"&gt;here&lt;/a&gt; and Free Code Camp has an amazing video on YouTube as well which can be found &lt;a href="https://www.youtube.com/watch?v=fmyvWz5TUWg"&gt;here&lt;/a&gt;. Bear in mind both of these technologies are going to be extremely slow to start learning and it's going to take a huge amount of time and practice in order to become proficient in either of these technologies. But after you've created a bunch of practice projects and examples most learn to love Ruby and Rails.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Frontend
&lt;/h2&gt;

&lt;p&gt;Now unlike the backend, the frontend of the web application you are building will consist almost definitely consist of JavaScript and it is extremely helpful to know other technologies such as HTML and CSS which make up the building blocks of the entire internet.&lt;/p&gt;

&lt;h3&gt;
  
  
  HTML
&lt;/h3&gt;

&lt;p&gt;HTML or HyperText Markup Language is going to be the main building block in which you organize your webpage. It can be combined with CSS in order to help style the document or it can have JavaScipt added in order to manipulate it. HTML is extremely easy to learn but difficult to master with things such as semantic HTML becoming more and more important in modern programming. If you are planning on learning HTML, W3Schools will be your best friend. They have an extremely extensive guide on nearly every single tag or element within HTML and will be your one-stop-shop for all your HTML questions. You can find their website &lt;a href="https://www.w3schools.com/html/"&gt;here&lt;/a&gt;. learn HTML is also a great resource for getting started as well and they can be found &lt;a href="https://www.learn-html.org/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  CSS
&lt;/h3&gt;

&lt;p&gt;CSS or cascading style sheets is a style sheet language meant to describe the presentation of a document written within a markup language. If you want to change anything to how your page looks, CSS is where you are going to do it. In this way, CSS can be extremely difficult to become proficient at since it has a huge number of different options for changing up your page. Although it is much like HTML as it is not technically difficult, it requires a large amount of design experience and practice in order to get great. Also, like HTML, W3Schools will be your best friend in this regard and there CSS section of their website can be found &lt;a href="https://www.w3schools.com/css/"&gt;here&lt;/a&gt;. Other than this, the best way to learn CSS is to learn all the display properties just jump in and experiment with as many commands as you can until you can get a page looking just like how you wanted.&lt;/p&gt;

&lt;h3&gt;
  
  
  JavaScript
&lt;/h3&gt;

&lt;p&gt;First developed in the mid-'90s for the web browser Netscape, JS has taken of the world of frontend development with nearly every modern web browser utilizing JavaScript as its language of choice. JavaScript's main role within your frontend is to handle and manipulate the document with scripting. If you want a button to add or take away any element from your page, you are going to need to use JavaScript to do it. Many good resources for JavaScript exist with W3Schools also coming up with amazing tutorials and resources which can be found &lt;a href="https://www.w3schools.com/js/DEFAULT.asp"&gt;here&lt;/a&gt;. Free Code Camp also offers an amazing JavaScript course which can be found &lt;a href="https://www.freecodecamp.org/"&gt;here&lt;/a&gt;.&lt;/p&gt;

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

&lt;p&gt;Although many web applications can run on just JavaScript, HTML, and CSS alone, many modern frameworks exist nowadays for the language which allows for more robust integration of a web application's frontend. One example of these frameworks would be React, which was developed by Facebook in 2013. React since than has taken the web development world by storm with its ability to create reusable components which greatly reduces time when building large applications, it has become a near necessity to learn in order to break into the front end side of web development. React has their own tutorial available for free on their website which can be found &lt;a href="https://www.google.com/search?q=learn+react&amp;amp;oq=Learn+React&amp;amp;aqs=chrome.0.0i433i457j0j0i20i263j0l5.2291j0j9&amp;amp;sourceid=chrome&amp;amp;ie=UTF-8"&gt;here&lt;/a&gt; and Free Code Camp has an awesome web page on the subject which you can find &lt;a href="https://www.freecodecamp.org/news/learning-react-roadmap-from-scratch-to-advanced-bff7735531b6/"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>beginners</category>
    </item>
    <item>
      <title>How to Use Jest to Quickly Test Your JavaScript Applications</title>
      <dc:creator>Kyle Petersen</dc:creator>
      <pubDate>Mon, 16 Nov 2020 02:18:53 +0000</pubDate>
      <link>https://forem.com/kpete2017/how-to-use-jest-to-quickly-test-your-javascript-applications-2odo</link>
      <guid>https://forem.com/kpete2017/how-to-use-jest-to-quickly-test-your-javascript-applications-2odo</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;Jest is an extremely popular unit testing framework for JavaScript and is even the default unit testing packing for many of the largest frameworks and libraries such as React. Its popularity can mainly be boiled down to its absolute simplicity to implement which makes it perfect for vanilla JavaScript projects.&lt;/p&gt;

&lt;h1&gt;
  
  
  Install Node.js
&lt;/h1&gt;

&lt;p&gt;In order to run Jest, you are first going to need to have Node.js. To do this, navigate &lt;a href=""&gt;here&lt;/a&gt; and select your appropriate operating system.&lt;/p&gt;

&lt;h1&gt;
  
  
  Initialize Our directory
&lt;/h1&gt;

&lt;p&gt;For this example, I'm going to create a completely empty directory/folder named jest_practice. Now we are going to cd into our new project and within our terminal, we are going to initialize Node Package Manager with &lt;code&gt;npm init&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Once you hit enter, you will be prompted to enter a bunch of information that will be used to create your Package.json file. For right now we can just use the defaults by leaving every option blank.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0ow96e0x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/amlop5urpowny98sqk55.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0ow96e0x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/amlop5urpowny98sqk55.png" alt="Alt Text" width="880" height="982"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now a file should have appeared within your project named package.json which should by default, look like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "jest_practice",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" &amp;amp;&amp;amp; exit 1"
  },
  "author": "",
  "license": "ISC"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After Node Package Manager is initialized we need to install Jest as a node module within the project. To do this we just need to run the command &lt;code&gt;npm i jest&lt;/code&gt; from within our terminal.&lt;/p&gt;

&lt;p&gt;After a short download, a new folder named node_modules should have appeared within our project as well as a file named package-lock.json.&lt;/p&gt;

&lt;p&gt;The last step of initialization we are going to need to do is make a small change to our package.json file. On line 7 where it currently says &lt;code&gt;"test": "echo \"Error: no test specified\" &amp;amp;&amp;amp; exit 1"&lt;/code&gt; we are going to change it to &lt;code&gt;test": "jest"&lt;/code&gt;. In the end, our package.json file should look like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "jest_practice",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "jest"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "jest": "^26.6.3"
  }
}

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

&lt;/div&gt;



&lt;h1&gt;
  
  
  Create Our Files
&lt;/h1&gt;

&lt;p&gt;As an example for Jest, we are going to test a simple two sum problem with Jest to make sure it is working properly. From our main directory, we are going to create the file TwoSum.js and TwoSum.test.js. Once these two files are created we are going to first jump into our TwoSum.js file.&lt;/p&gt;

&lt;h1&gt;
  
  
  Editing our TwoSum.js File
&lt;/h1&gt;

&lt;p&gt;From within our file, we are going to create a JavaScript function just like any other and name it twoSum. For simplicity's sake, I am going to go ahead and fill in the solution to the problem within the function below so we can immediately jump to testing it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function twoSum(nums, target) {
    const map = {};
    for (let i = 0; i &amp;lt; nums.length; i++) {
      const another = target - nums[i];

      if (another in map) {
        return [map[another], i];
      }
      map[nums[i]] = i;
    }
    return null;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The last only other thing we need to do tho this file is to export this function by writing &lt;code&gt;module.exports = twoSum;&lt;/code&gt; right below it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function twoSum(nums, target) {
    const map = {};
    for (let i = 0; i &amp;lt; nums.length; i++) {
      const another = target - nums[i];

      if (another in map) {
        return [map[another], i];
      }
      map[nums[i]] = i;
    }
    return null;
}

module.exports = twoSum;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Setting Up Our Jest Testing
&lt;/h1&gt;

&lt;p&gt;Now that we have our problem finished, all we need to do is set up our tests to make sure it is working properly. To do this, navigate to the TwoSum.test.js file we had created earlier. From here, we are going to start off by creating a requiring in our finished two sum function by typing &lt;code&gt;const twoSum = require(./TwoSum);&lt;/code&gt; on line 1.&lt;/p&gt;

&lt;p&gt;After we have required our twoSum function, we are going to start building our test by using test(). The first parameter of the test function is going to be a message describing what specifically we are testing. In the first test, we are just going to see if one of our inputs equals an expected output so our message will me &lt;code&gt;test("Given an array integers and a target, the function should return two indices such that they add up to the target.")&lt;/code&gt;. The second parameter of the test() function will be the actual expected input and output which we will format like so.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test("Given an array integers and a target, the function should return two indices such that they add up to the target.", () =&amp;gt; {
    expect(twoSum([2,7,11,15], 9)).toEqual([0,1])
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the end, the TwoSum.test.js file should end up looking like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const twoSum = require('./TwoSum')

test("Given an array integers and a target, the function should return two indices such that they add up to the target.", () =&amp;gt; {
    expect(twoSum([2,7,11,15], 9)).toEqual([0,1])
})

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

&lt;/div&gt;



&lt;p&gt;Now if we run the command &lt;code&gt;npm run test&lt;/code&gt; within our terminal we should get a passing test!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--asTX_PXg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/a6x4luto1xp1v9a8tptb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--asTX_PXg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/a6x4luto1xp1v9a8tptb.png" alt="Alt Text" width="880" height="440"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's the super fast way to get Jest up and running on your project. Keep in mind though that probably going to need to test much more if we want to make sure our code is full proof and for this, Jest has a ton of different Matchers. For example, if we wanted to make sure our function returned null if there were no two indices that equaled the target we could use the matcher .toBeNull instead of .toEqual or we could even check if our function returns values greater than or less than certain values by using the .toBeGreaterThan() or .toBeLessThan(). For more details on Matchers you can reach the Jest documentation &lt;a href="https://jestjs.io/docs/en/using-matchers"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>testing</category>
    </item>
    <item>
      <title>How I Made a Restaurant Finder App With React Native Part 2</title>
      <dc:creator>Kyle Petersen</dc:creator>
      <pubDate>Mon, 09 Nov 2020 02:39:40 +0000</pubDate>
      <link>https://forem.com/kpete2017/how-to-create-a-restaurant-finder-app-in-react-native-part-2-56gj</link>
      <guid>https://forem.com/kpete2017/how-to-create-a-restaurant-finder-app-in-react-native-part-2-56gj</guid>
      <description>&lt;h2&gt;
  
  
  Get API Credentials
&lt;/h2&gt;

&lt;p&gt;We now have our user's location to find our restaurants stored safely within our components state! But before we can make our API call to the Google Places API to receive our list of restaurants, we need to get an API key from Google. Go ahead and open a  web browser and navigate to the &lt;a href="https://console.developers.google.com/apis/credentials?folder=&amp;amp;organizationId=&amp;amp;project=what-to-do-294220" rel="noopener noreferrer"&gt;Google developer console&lt;/a&gt; and log in with your Google account. From here you are going to click the drop-down which says "select a project" and then click on a "new project". From here you can name the project. We are also going to leave the organization section blank for now.&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%2Fwr55o85w51ifd78iqiag.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%2Fwr55o85w51ifd78iqiag.png" alt="Alt Text" width="800" height="560"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After your project is created, you are then going to go to the library tab and search for the Google Places API within the marketplace. Once found go ahead and add the library to your account.&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%2Fqhug3r4dv2n0ynivk0f4.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%2Fqhug3r4dv2n0ynivk0f4.png" alt="Alt Text" width="800" height="505"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After the Google places API is added to your Google developer account, find and click on the tab that says credentials from the home page. Once in the credentials tab, you are going to press the plus button with the text "Create Credentials" next to it and then select the "API key" option. Under the API keys section, there should be a new key labeled API key 1.&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%2Fcwtmkpc5vtxfc8d9nbn5.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%2Fcwtmkpc5vtxfc8d9nbn5.png" alt="Alt Text" width="800" height="339"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Underneath the "key" column is going to be the API key we are going to use in our project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating Our Fetch URL
&lt;/h2&gt;

&lt;p&gt;Now that we have the necessary credentials in order to access the Google Places API, we are going to make a fetch call in order to search for nearby restaurants when our "Search Restaurants" touchable opacity is clicked. &lt;/p&gt;

&lt;p&gt;The first thing we are going to do is create our handleRestaurantSearch method. Within our App class above our render function, go ahead and add the lines&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;handleRestaurantSearch = () =&amp;gt; {

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

&lt;/div&gt;



&lt;p&gt;Now within our new method, we are going to add the building blocks of our URL string to make the API call. The first part of which begins with the base URL. Let us create a constant variable within our method named URL and set it equal to "&lt;a href="https://maps.googleapis.com/maps/api/place/nearbysearch/json?" rel="noopener noreferrer"&gt;https://maps.googleapis.com/maps/api/place/nearbysearch/json?&lt;/a&gt;". The variable should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const url  = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json?'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After this, we need to add the user's location to the string which we have stored within our app's state.&lt;br&gt;
We are going to create a constant variable named location and set it equal to our latitude and longitude like so.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const location = `location=${this.state.latitude},${this.state.longitude}`;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that, we need to specify the radius of our search in meters, the type of search we are doing, and our API key. To do this we can create another three variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const radius = '&amp;amp;radius=2000';
    const type = '&amp;amp;keyword=restaurant';
    const key = '&amp;amp;key=&amp;lt;ENTER YOUR API KEY HERE&amp;gt;';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At the very end, we can add all our string variables together to create our final string which will be passed as our API call.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const restaurantSearchUrl = url + location + radius + type + key;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the end, your handleRestaurantSearch method should look like so.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  handleRestaurantSearch = () =&amp;gt; {
    const location = `location=${this.state.latitude},${this.state.longitude}`;
    const radius = '&amp;amp;radius=2000';
    const type = '&amp;amp;keyword=restaurant';
    const key = '&amp;amp;key=&amp;lt;YOUR API KEY&amp;gt;';
    const restaurantSearchUrl = url + location + radius + type + key;

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

&lt;/div&gt;



&lt;h1&gt;
  
  
  Fetching our Data
&lt;/h1&gt;

&lt;p&gt;Now that our string is built, we can make a fetch for our data. Below our new variables, we create a fetch request using the JavaScript fetch() function, and within the parameters, enter our restaurantSearchUrl.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fetch(restaurantSearchUrl)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since fetch is a promise, we are going to use a .then right below our fetch request to handle when the promise is resolved and parse the JSON we were sent from Google.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.then(response =&amp;gt; response.json())
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that promise is resolved, we are going to change the restaurantList key within our state to match whatever we were sent back by this fetch request.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.then(result =&amp;gt; this.setState({restaurantList: result}))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our handleRestaurantSearch method should now look something like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  handleRestaurantSearch = () =&amp;gt; {
    const url  = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json?'
    const location = `location=${this.state.latitude},${this.state.longitude}`;
    const radius = '&amp;amp;radius=2000';
    const type = '&amp;amp;keyword=restaurant';
    const key = '&amp;amp;key=&amp;lt;YOUR API KEY&amp;gt;';
    const restaurantSearchUrl = url + location + radius + type + key;
    fetch(restaurantSearchUrl)
      .then(response =&amp;gt; response.json())
      .then(result =&amp;gt; this.setState({restaurantList: result}))
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now in order to call our handleRestaurantSearch method, we need to create an event listener within our TouchableOpacity. within our &lt;code&gt;&amp;lt;TouchableOpacity&amp;gt;&lt;/code&gt; tag we are going to add the following lines to create an onPress event listener.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;TouchableOpacity onPress={() =&amp;gt; this.handleRestaurantSearch()}&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are also going to add a console.log() to our render function to test to see whether our restaurant list is showing up within our state. To do this we can add console.log(this.state.restaurantList); right below our render method but above the return statement.&lt;/p&gt;

&lt;p&gt;Now from our physical device or emulator, we can press "Search Restaurants" and within our terminal, we should see a long list of JSON describing 20 nearby restaurants.&lt;/p&gt;

&lt;h1&gt;
  
  
  Displaying Our List of Restaurants
&lt;/h1&gt;

&lt;p&gt;Now that we have our list of restaurants ready to go we can now list them within our FlatList. Within our FlatList tag we are going to set a few attributes.&lt;/p&gt;

&lt;p&gt;The first attribute we are going to set is the data attributes. We are going to assign this to our restaurantList's results we have contained within our state.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;FlatList
  data={this.state.restaurantList.results}
&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are going to then create a keyExtractor to make sure each item on the list has a unique identifier. We are going to set each item's key to its place_id.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;FlatList
  data={this.state.restaurantList.results}
  keyExtractor={(item) =&amp;gt; item.place_id}
&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The last thing we need to do before our FlatList is complete is to add the renderItem attribute. Here we can call what kind of tags our list is going to use. For this example, we are just going to use a text tag that will display a nearby restaurant's name. I'm also going to add the tiniest bit of styling to our list to make it more visible once finished. To do this add the following attributes after the keyExtractor.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        &amp;lt;FlatList  
          data={this.state.restaurantList.results}
          keyExtractor={(item) =&amp;gt; item.place_id}
          renderItem={({item}) =&amp;gt; (
            &amp;lt;Text&amp;gt;{item.name}&amp;lt;/Text&amp;gt;
          )}
          style={{backgroundColor: 'grey', width: '80%', margin: 60, padding: 5}}
        /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After this, we should be finished with our list meaning that when you click on the "Search Restaruants" TouchableOpacity within your phone or emulator, we should see a list of restaurants that looks like so.&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%2F36ytkv5bg5rceogz8whs.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%2F36ytkv5bg5rceogz8whs.png" alt="Alt Text" width="722" height="1546"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the end. Our entire App.js file should look like so.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View, FlatList, TouchableOpacity } from 'react-native';
import * as Permissions from 'expo-permissions';
import * as Location from 'expo-location';


export default class App extends React.Component {

  state = { 
    hasLocationPermission: false,
    latitude: 0,
    longitude: 0,
    restaurantList: []
  }

  componentDidMount() {
    this.getLocationAsync();
  }

  async getLocationAsync () {
    const { status } = await Permissions.askAsync(
      Permissions.LOCATION
    );
    if (status === 'granted') {
      let location = await Location.getCurrentPositionAsync({});
      this.setState({
        hasLocationPermissions: true,
        latitude: location.coords.latitude,
        longitude: location.coords.longitude,
      });
    } else {
      alert('Location permission not granted');
    }
  };

  styles = StyleSheet.create({
    container: {
      flex: 1,
      backgroundColor: '#fff',
      alignItems: 'center',
      justifyContent: 'center',
    },
  });

  handleRestaurantSearch = () =&amp;gt; {
    console.log("here")
    const url  = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json?'
    const location = `location=${this.state.latitude},${this.state.longitude}`;
    const radius = '&amp;amp;radius=2000';
    const type = '&amp;amp;keyword=restaurant';
    const key = '&amp;amp;key=AIzaSyCTG8tfRBCabaCP-enskC2akmNVBvaOAAs';
    const restaurantSearchUrl = url + location + radius + type + key;
    fetch(restaurantSearchUrl)
      .then(response =&amp;gt; response.json())
      .then(result =&amp;gt; this.setState({restaurantList: result}))
      .catch( e =&amp;gt; console.log(e))
  }

  render() {
    console.log(this.state.restaurantList.results)
    return (
      &amp;lt;View style={this.styles.container}&amp;gt;
        &amp;lt;FlatList  
          data={this.state.restaurantList.results}
          keyExtractor={(item) =&amp;gt; item.place_id}
          renderItem={({item}) =&amp;gt; (
            &amp;lt;Text&amp;gt;{item.name}&amp;lt;/Text&amp;gt;
          )}
          style={{backgroundColor: 'grey', width: '80%', margin: 60, padding: 5}}
        /&amp;gt;
        &amp;lt;TouchableOpacity onPress={() =&amp;gt; this.handleRestaurantSearch()}&amp;gt;
          &amp;lt;Text style={{backgroundColor: 'grey', color: 'white', padding: 20, marginBottom: 50}}&amp;gt;Search Restaurants&amp;lt;/Text&amp;gt;
        &amp;lt;/TouchableOpacity&amp;gt;
        &amp;lt;StatusBar style="auto" /&amp;gt;
      &amp;lt;/View&amp;gt;
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that is how to create a nearby restaurant finder within React-Native! Note that tons of information such as the restaurant's address, rating, and photos are also given with our API call which we can also use within our list. If you wanted to do a keyword search to find a specific restaurant instead of just a list of nearby restaurants you can use the Google Places API &lt;a href="https://developers.google.com/places/web-service/search" rel="noopener noreferrer"&gt;text search&lt;/a&gt; instead. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>How I Made a Restaurant Finder App with React Native Part 1</title>
      <dc:creator>Kyle Petersen</dc:creator>
      <pubDate>Mon, 02 Nov 2020 03:02:35 +0000</pubDate>
      <link>https://forem.com/kpete2017/how-i-made-a-restaurant-finder-app-with-react-native-part-1-1aic</link>
      <guid>https://forem.com/kpete2017/how-i-made-a-restaurant-finder-app-with-react-native-part-1-1aic</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;React Native has been a game-changer in mobile development ever since it was first released back in March of 2015. Due to its flexibility, extensive libraries, and simplicity to learn for those already familiar with React. It has since then, been adopted by some of the largest companies on earth to build their mobile applications. Today, I would like to show you how I created a restaurant finder app using the Google Places API for a complete React Native beginner.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;For this project, we are going to need a few things downloaded. We are also going to be using Expo CLI for our app.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First Download &lt;a href="https://nodejs.org/en/download/" rel="noopener noreferrer"&gt;Node Package Manager&lt;/a&gt; to your appropriate operating system.&lt;/li&gt;
&lt;li&gt;Then, within your terminal install Expo with &lt;code&gt;npm install -g expo-cli&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Also, download the app Expo on your mobile device if you would like to test the app on your own physical hardware.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Initialization
&lt;/h2&gt;

&lt;p&gt;To initialize a new react native project with Expo, run the command&lt;br&gt;
&lt;code&gt;expo init &amp;lt;name of project&amp;gt; --npm&lt;/code&gt;. In this case, we are going to name the project restaurant_finder. Once prompted to select a template, choose the 'blank' one for now. Once you open the project within a text editor of your choice, you should have a file structure similar to 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3b2p0admqckyrlt797r0.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%2F3b2p0admqckyrlt797r0.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: the &lt;code&gt;--npm&lt;/code&gt; flag at the end of our command tells Expo to install all the dependencies with node package manager. Expo defaults to using yarn otherwise. Make sure you do not mix using these two package managers or it will cause errors.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We are going to now change our current directory into our project with &lt;code&gt;cd restaurant_finder&lt;/code&gt; and install a couple of extra packages by running &lt;code&gt;expo install expo-location&lt;/code&gt; and &lt;code&gt;expo install expo-permissions&lt;/code&gt;. Once both of those packages are installed, we are going to start our project with &lt;code&gt;npm start&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;A new window should open up with the metro bundler front and center.&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%2Fl8tj16sxa6ssvgx2yywi.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%2Fl8tj16sxa6ssvgx2yywi.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can scan the barcode in the bottom left corner with your device to open the app we are working on. At the moment you should just see a blank screen with text that says "Open up App.js to start working on your app!".&lt;br&gt;
We are going to do exactly that!&lt;/p&gt;

&lt;p&gt;Go ahead and open app.js within your text editor and you should see a bunch of code that looks like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';

export default function App() {
  return (
    &amp;lt;View style={styles.container}&amp;gt;
      &amp;lt;Text&amp;gt;Open up App.js to start working on your app!&amp;lt;/Text&amp;gt;
      &amp;lt;StatusBar style="auto" /&amp;gt;
    &amp;lt;/View&amp;gt;
  );
}
const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Changing Our Component into a Class
&lt;/h2&gt;

&lt;p&gt;Since we are going to be doing quite a bit of state manipulation we are going to go ahead and translate our functional component into a class-based component. &lt;/p&gt;

&lt;p&gt;To do this we are going to replace the word 'function' with 'class' within our declaration and replacing the parenthesis with 'extends React.Component'. &lt;/p&gt;

&lt;p&gt;After this, we need to remove the 'const' before 'styles' and move the whole object between our curly braces. Since our styles function is now with the class, within our  tag we need to call it as &lt;code&gt;this.styles.container&lt;/code&gt; instead of just &lt;code&gt;styles.container&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;The last thing we need to do is add the render() method to our class and wrapping our return within it. &lt;/p&gt;

&lt;p&gt;After these changes, your file should look like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';

export default class App extends React.Component{
  render() {
    return (
      &amp;lt;View style={this.styles.container}&amp;gt;
        &amp;lt;Text&amp;gt;Open up App.js to start working on your app!&amp;lt;/Text&amp;gt;
        &amp;lt;StatusBar style="auto" /&amp;gt;
      &amp;lt;/View&amp;gt;
    );
  }

  styles = StyleSheet.create({
    container: {
      flex: 1,
      backgroundColor: '#fff',
      alignItems: 'center',
      justifyContent: 'center',
    },
  });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are going to go ahead and import a few things from the react-native library to display our list of nearby restaurants to the user. From line 3 where it currently says&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { StyleSheet, Text, View } from 'react-native';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are going to go ahead and add a FlatList and a TouchableOpacity. Line three should then look like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { StyleSheet, Text, View, FlatList, TouchableOpacity } from 'react-native';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A FlatList is an area where we are going to display our list of restaurants and a TouchableOpacity, for all intents and purposes, is just a button that will be used to initialize the search when pressed.&lt;/p&gt;

&lt;p&gt;Lastly, we are going to import libraries that will allow us to get the user's location and location permission by adding&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import * as Location from 'expo-location';
import * as Permissions from 'expo-permissions';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Creating our FlatList and TouchableOpacity
&lt;/h2&gt;

&lt;p&gt;We are going to go ahead and delete the &lt;code&gt;&amp;lt;Text&amp;gt;Open up App.js to start working on your app!&amp;lt;/Text&amp;gt;&lt;/code&gt; and revert our app to a completely white screen. Then in the same space between the  tag, we are going to add our TouchableOpacity tag Like so.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    &amp;lt;View style={this.styles.container}&amp;gt;
      &amp;lt;TouchableOpacity&amp;gt;
      &amp;lt;/TouchableOpacity&amp;gt;
      &amp;lt;StatusBar style="auto" /&amp;gt;
    &amp;lt;/View&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Between the two touchable opacity tags, we are going to then add a Text tag to the button that says "Search Restaurants".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    &amp;lt;View style={this.styles.container}&amp;gt;
      &amp;lt;TouchableOpacity&amp;gt;
        &amp;lt;Text&amp;gt;Search Restaurants&amp;lt;/Text&amp;gt;
      &amp;lt;/TouchableOpacity&amp;gt;
      &amp;lt;StatusBar style="auto" /&amp;gt;
    &amp;lt;/View&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are also going to style the text tag just a tiny bit by adding &lt;code&gt;style={{backgroundColor: 'grey', color: 'white', padding: 5, marginBottom: 50}}&lt;/code&gt; to the Text tag's parameters like so.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Text style={{backgroundColor: 'grey', color: 'white', padding: 20, marginBottom: 50}}&amp;gt;Search Restaurants&amp;lt;/Text&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now right above our TouchableOpacity, we are going to add our FlatList to display our list of restaurants. Our FlatList can just have a self-closing tag as well like so &lt;code&gt;&amp;lt;FlatList /&amp;gt;&lt;/code&gt;. We are going to come back to our FlatList tag once we obtain our list of data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting the User's Location
&lt;/h2&gt;

&lt;p&gt;We also need a place to store our list of restaurants and the user location as well as a variable to tell our component whether location permission has been granted. To achieve this we are going to create a state for our component. To do this, we are going to add these lines.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;state = { 
  hasLocationPermission: false,
  latitude: 0,
  longitude: 0,
  restaurantList: []
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we have our button ready to be pushed and state ready to be manipulated, we just need to tell it to grab the list of nearby restaurants when pushed. To do this we are going to need to first get location permission from the user's device and then get their location in coordinates. To achieve this we are going to use the componentDidMount() method which will be called when the app component is first mounted. To do this go ahead and add these lines within your app class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  componentDidMount() {

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

&lt;/div&gt;



&lt;p&gt;We are now going to create a new async method that will first ask the user's location and collect their coordinates accordingly. Right below our componentDidMount method, we are going to go ahead and create the method, getLocationAsync like so.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async getLocationAsync () {

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

&lt;/div&gt;



&lt;p&gt;Within our method, we are first going to ask what the user's device for permission.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async getLocationAsync () {
    const { status } = await Permissions.askAsync(
      Permissions.LOCATION
    );
  };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and if that permission is granted, we are then going to change our hasLocationPermission and state to true and change our location state to reflect the user's coordinates by using the setState method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  async getLocationAsync () {
    const { status } = await Permissions.askAsync(
      Permissions.LOCATION
    );
    if (status === 'granted') {
      let location = await Location.getCurrentPositionAsync({});
      this.setState({
        hasLocationPermissions: true,
        latitude: location.coords.latitude,
        longitude: location.coords.longitude,
      });
    } else {
      alert('Location permission not granted');
    }
  };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then to make sure this method gets called during the first creation of our component go ahead and call the method within our componentDidMount() method like so.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;componentDiDMount() {
  this.getLocationAsync();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After all this, our entire app class should look like so.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View, FlatList, TouchableOpacity } from 'react-native';
import * as Permissions from 'expo-permissions';
import * as Location from 'expo-location';


export default class App extends React.Component {

  state = { 
    hasLocationPermission: false,
    latitude: 0,
    longitude: 0,
    restaurantList: []
  }

  componentDidMount() {
    this.getLocationAsync();
  }

  async getLocationAsync () {
    const { status } = await Permissions.askAsync(
      Permissions.LOCATION
    );
    if (status === 'granted') {
      let location = await Location.getCurrentPositionAsync({});
      this.setState({
        hasLocationPermissions: true,
        latitude: location.coords.latitude,
        longitude: location.coords.longitude,
      });
    } else {
      alert('Location permission not granted');
    }
  };

  styles = StyleSheet.create({
    container: {
      flex: 1,
      backgroundColor: '#fff',
      alignItems: 'center',
      justifyContent: 'center',
    },
  });

  render() {
    console.log(this.state.latitude, this.state.longitude)
    return (
      &amp;lt;View style={this.styles.container}&amp;gt;
        &amp;lt;FlatList  /&amp;gt;
        &amp;lt;TouchableOpacity&amp;gt;
          &amp;lt;Text style={{backgroundColor: 'grey', color: 'white', padding: 20, marginBottom: 50}}&amp;gt;Search Restaurants&amp;lt;/Text&amp;gt;
        &amp;lt;/TouchableOpacity&amp;gt;
        &amp;lt;StatusBar style="auto" /&amp;gt;
      &amp;lt;/View&amp;gt;
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Tada! now we have our user's location stored safely within our state. We can now use that location to get our list of restaurants nearby in part two!&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>beginners</category>
      <category>react</category>
      <category>mobile</category>
    </item>
    <item>
      <title>How to Add Google Maps to Your Expo React Native Project</title>
      <dc:creator>Kyle Petersen</dc:creator>
      <pubDate>Sun, 25 Oct 2020 23:12:03 +0000</pubDate>
      <link>https://forem.com/kpete2017/how-to-add-google-maps-to-your-expo-react-native-project-2fe5</link>
      <guid>https://forem.com/kpete2017/how-to-add-google-maps-to-your-expo-react-native-project-2fe5</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;React native has taken the mobile development industry by storm since its unveiling in 2015. Since then it has been adopted by some of the world's largest tech companies such as Facebook, Airbnb, Uber, Or Pinterest. With that in mind, it should be a pretty common requirement in many applications to use the world's most popular mapping app, Google Maps. In this blog, I will show you how to use Google Maps in your own react native apps.&lt;/p&gt;

&lt;h1&gt;
  
  
  Getting Set Up
&lt;/h1&gt;

&lt;p&gt;To complete this task we are going to need to install the component &lt;a href="https://github.com/react-native-maps/react-native-maps" rel="noopener noreferrer"&gt;react-native-apps&lt;/a&gt; which was created by AirBnB for their own app. This is in addition to our own version of &lt;a href="https://docs.expo.io/get-started/installation/" rel="noopener noreferrer"&gt;Expo&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Before we begin please make sure you have &lt;a href="https://www.npmjs.com/get-npm" rel="noopener noreferrer"&gt;Node Package Manager or npm&lt;/a&gt; as well as &lt;a href="https://classic.yarnpkg.com/en/docs/install/#mac-stable" rel="noopener noreferrer"&gt;Yarn&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To get us started, we are going to need to install Expo onto our machine. To do this we can run the command within our terminal &lt;code&gt;npm install --global expo-cli&lt;/code&gt;. After Expo has completed we can go ahead and create our project with &lt;code&gt;expo init &amp;lt;project name&amp;gt;&lt;/code&gt;. For this instance, we are going to name our project "test_app". After this, we will be presented with a few options to get our project started. We will then choose the option "blank".&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%2Fcq8mrio6zbvjnibrnozj.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%2Fcq8mrio6zbvjnibrnozj.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After our project has been successfully created we are then going to change the directory into the project we had just created using &lt;code&gt;cd test_app&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Within our main directory, we are going to run the command:&lt;br&gt;
&lt;code&gt;npm install react-native-maps --save-exact&lt;/code&gt;&lt;br&gt;
or&lt;br&gt;
&lt;code&gt;yarn add react-native-maps -E&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: Expo defaults to using yarn as its package manager. Since it will cause problems to mix package managers make sure you only use one or the other.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After this, we can open our file with any text editor of your choice. In this instance, I will be using VSCode.&lt;/p&gt;

&lt;h1&gt;
  
  
  Adding Google Maps to Our Created Project
&lt;/h1&gt;

&lt;p&gt;From within our parent directory, there should be a file named App.js. Opening it should look like below.&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%2Fb0gi1odxe2a2pilifieb.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%2Fb0gi1odxe2a2pilifieb.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are going to import our MapView from the react-native-apps component. To do this we are going to add &lt;code&gt;import MapView from 'react-native-maps';&lt;/code&gt; to line 4. After this, we now have access to the MapView tag&lt;/p&gt;

&lt;p&gt;Now within our return statement within our app function, we can add our map to make it show up on our react-native app. We can delete the Text tag from line 10 and add our own tag &lt;code&gt;&amp;lt;MapView&amp;gt;&amp;lt;/MapView&amp;gt;&lt;/code&gt;. Your App.js file should now 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F43ru3uw5hev7aglcfbzd.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%2F43ru3uw5hev7aglcfbzd.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now our map is initiated within our app, but you can't see it anywhere. To fix this we are going to need to add a bit of styling to the mix. Within our MapView tag, we are going to go ahead and add &lt;code&gt;style={StyleSheet.absoluteFillObject}&lt;/code&gt; which will make the map fill the entire screen of the device. Make sure we also add &lt;code&gt;provider={MapView.PROVIDER_GOOGLE}&lt;/code&gt; to make sure our map application defaults to Google Maps.&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%2Focshadkeu77k4nm994ln.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%2Focshadkeu77k4nm994ln.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And there we go! We now have a fully functioning map running within React Native. Further customization of the map can be made with additional styling. Further modification of the map including its initial starting location instructions can also be found &lt;a href="https://github.com/react-native-maps/react-native-maps/blob/master/docs/mapview.md" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>reactnative</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to Create User Authentication in a Ruby on Rails API</title>
      <dc:creator>Kyle Petersen</dc:creator>
      <pubDate>Mon, 19 Oct 2020 03:14:19 +0000</pubDate>
      <link>https://forem.com/kpete2017/how-to-create-user-authentication-in-a-ruby-on-rails-api-5ajf</link>
      <guid>https://forem.com/kpete2017/how-to-create-user-authentication-in-a-ruby-on-rails-api-5ajf</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Ruby on Rails, for many years now, has been an extremely popular and influential framework that allows a developer to quickly and cost-effectively build and deploy fully functioning backends. With that in mind, in nearly every complex web application the problem of user authentication will most definitely come into play. This guide will attempt to explain how you can quickly build secure authentication for your web application with Ruby on Rails.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;Make sure the below items are installed on your machine before we begin.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.ruby-lang.org/en/documentation/installation/" rel="noopener noreferrer"&gt;Ruby&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://installrails.com/" rel="noopener noreferrer"&gt;Ruby On Rails&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Creating our project
&lt;/h2&gt;

&lt;p&gt;Just like how we would normally create any Ruby on Rails project, we are going to run &lt;code&gt;rails new &amp;lt;name of project&amp;gt; --api&lt;/code&gt;. We are then going to need to change a few things in the gem file. Within the file "Gemfile" on line 17 there should be a commented line which reads &lt;code&gt;gem 'bcrypt', '~&amp;gt; 3.1.7'&lt;/code&gt; or something similar. Un-comment it out and add the line &lt;code&gt;gem 'jwt'&lt;/code&gt; below as well. It should then end up looking 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F54y9rjwx0mrvy3g4hxt9.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%2F54y9rjwx0mrvy3g4hxt9.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
After both are added run the command &lt;code&gt;bundle install&lt;/code&gt; to add both the gems to your project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating our User model
&lt;/h2&gt;

&lt;p&gt;Next, we are going to create our user model in which we are going to be using to authenticate. From our terminal, we are going to run &lt;code&gt;rails g scaffold User username:uniq password:digest&lt;/code&gt;. It is important to note that the digest at the end of &lt;code&gt;password:digest&lt;/code&gt; means that the user's password will not be stored as plain text within our database and adds a few extra goodies to our project. After our model has completed we are going to migrate our database using the command &lt;code&gt;rails db:migrate&lt;/code&gt;. After our migration we need to add the lines &lt;code&gt;validates :email, presence: true, uniqueness: true&lt;/code&gt; to the user.rb file within our models folder. This makes sure that when a new user is created that the username is unique within the 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ff132x839g8gncz8td3a6.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%2Ff132x839g8gncz8td3a6.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Application Controller
&lt;/h2&gt;

&lt;p&gt;We are now going to create our Authenticate method from within our application controller file so any of our other controllers can access it when needed. Creating an empty method, our file should look 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fn0vu57j2mbtj2ym3irsz.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%2Fn0vu57j2mbtj2ym3irsz.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first thing we are going to check within our method is whether authorization headers were sent. To do that we can create a small if statement.&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%2Fesjfx0nicktferquxxrg.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%2Fesjfx0nicktferquxxrg.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After we check whether the auth header was sent, we can then begin to decode our JWT token that should have been sent within the auth header. We should wrap the next few things within a begin rescue block of code which works similarly to a try-catch in other languages. &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%2Foa6mnpx2lc0x894tep6u.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%2Foa6mnpx2lc0x894tep6u.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Within our begin/ rescue block, we should then decode our JWT token, find our payload, and get our user_id so we can then find our User within our database. To do this we will create a method named secret and token.&lt;/p&gt;

&lt;p&gt;Our secret method will find a key within a secret key base which we can access like so.&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%2Fmgukwfpb9h6mt7eo966e.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%2Fmgukwfpb9h6mt7eo966e.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can then create our Token method which will access the second item within the auth_headers array.&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%2Fjvo1edejcrjl8ka0g82u.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%2Fjvo1edejcrjl8ka0g82u.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Afterward, those two methods are created we can finish our Authorize method. All we need to do is get the user_id from our payload and then use that to find our authorized user. &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%2F8mfylfyh2xawt3ct4wzx.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%2F8mfylfyh2xawt3ct4wzx.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For future application, we are going to add one last method to our application_controller which will be our create_token method.&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%2Fytufuzilihfspz9g4fdb.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%2Fytufuzilihfspz9g4fdb.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The last thing we need within our Application controller class, for now, is to specify ours before action. All we are going to say here is that before anything else is attempted within our application controller we must authenticate first. to do that all we need to do is add &lt;code&gt;before_action :authenticate&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In the end, our application_controller.rb file should look 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbinrifu9tsh6hvt936mj.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%2Fbinrifu9tsh6hvt936mj.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  User Controller
&lt;/h2&gt;

&lt;p&gt;Since our authentication controller is finished we will also want to make a change to our User controller. Specifically, we need to create a token whenever a new user is created. To do this we can use the create_token method we had made earlier within our create method like so. &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%2F0qibkp1kkok5izg4a5cz.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%2F0qibkp1kkok5izg4a5cz.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Authentication Controller
&lt;/h2&gt;

&lt;p&gt;For someone who is not creating a user for the first time, we need to create a login method. We will do this in a controller called AUthentication Controller. To create this controller rin &lt;code&gt;rails g controller authentication&lt;/code&gt;. A new file should then exist with your controller folder name authentication_controller.rb. Within this file, there should only be an empty class named AuthenticationController.&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%2Fd63so6l9bytesn33kc1w.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%2Fd63so6l9bytesn33kc1w.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Within here we will then create our login method and make sure that it skips our authenticate method we had created earlier.&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%2Fzl5axa29zerxzw8i3j42.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%2Fzl5axa29zerxzw8i3j42.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Within our method, we must first find our specific user using ruby's find_by method and then authenticate that user once found with our authenticate method we had created in our application_controller.&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%2F1vy4t003vil5qskhovpk.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%2F1vy4t003vil5qskhovpk.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After we authenticate our user. We can then use the methods we had created earlier within our application controller to make a new JWT token for the user and also send all of the user data as JSON with the render method.&lt;/p&gt;

&lt;p&gt;In the end, our authentication_controller.rb file should look like so.&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%2Frh4k0a4l018tbftqgmub.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%2Frh4k0a4l018tbftqgmub.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Routes
&lt;/h2&gt;

&lt;p&gt;The final step before we are finished with our fully functioning user authentication is to specify our login route. From within routs.rb which is located within the config controller, add &lt;code&gt;post 'login', to: 'authentication#login'&lt;/code&gt; which should send any /login request directly to our login method. The file should end up looking 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fw59hywrqb1htbmioxuvl.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%2Fw59hywrqb1htbmioxuvl.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>ruby</category>
      <category>webdev</category>
    </item>
    <item>
      <title>My Coding Bootcamp VS College Curriculum</title>
      <dc:creator>Kyle Petersen</dc:creator>
      <pubDate>Mon, 12 Oct 2020 01:54:31 +0000</pubDate>
      <link>https://forem.com/kpete2017/my-coding-bootcamp-vs-college-curriculum-3jf6</link>
      <guid>https://forem.com/kpete2017/my-coding-bootcamp-vs-college-curriculum-3jf6</guid>
      <description>&lt;p&gt;Hey there! My name is Kyle and I've completed around 80 out of 120 computer science credits at the Metropolitan State University of Denver and I have also graduated from Flatiron School's in-person software engineering program. I'm here to compare and contrast the differences in coding philosophy between the two mediums of education and talk about my personal experiences in both.&lt;/p&gt;

&lt;h2&gt;
  
  
  College
&lt;/h2&gt;

&lt;p&gt;At the Metropolitan State University of Denver, you are expected to take 120 credits at the minimum to receive a bachelor of science in computer science. Of the 120 credits, only 54 are your computer science classes. The rest are reserved for your general science classes as well as a required mathematics minor (30 credits), your gen eds (30 credits), and a small number of ancillary courses (6 credits).&lt;/p&gt;

&lt;p&gt;Within the computer science major, you are required to learning a wide variety of information about programming going all the way down to the binary level. Through your first few years in the program, you should expect to learn quite a bit of Java with a pretty heavy emphasis on programming convention. They will also begin to start you off with algorithms and data structures. You will also take computer organization and architecture classes where you will learn things such as binary, boolean logic, and assembly language. The last few years of your degree will put a strong emphasis on algorithms as well as in-depth knowledge of operating systems, principals of programming languages, and the development lifecycle in general.&lt;/p&gt;

&lt;p&gt;Many colleges will end up going over a very wide variety of subjects &lt;strong&gt;making their graduates a swiss army knife of knowledge in any computer science field they choose to go in&lt;/strong&gt;. Although some including myself found some frustration in taking the huge amount of general educations and science core classes as well as some of the lack of focus within the program itself. &lt;/p&gt;

&lt;h2&gt;
  
  
  Bootcamp
&lt;/h2&gt;

&lt;p&gt;In contrast, &lt;strong&gt;Flatirons was hyper-focused on gaining in-depth knowledge of a very particular set of subjects&lt;/strong&gt;. If you had chosen the software engineering path as I had, you would be learning about web development and a little bit of mobile dev related subjects. They put a large emphasis on Ruby and Ruby on Rails for backend development as well as React.js and Javascript for the front-end. Meaning, you should be able to build professional web applications on your own by the end of the program. Although these topics you will be required, &lt;strong&gt;you are encouraged to learn additional subjects&lt;/strong&gt; and you are in no means locked into only learning the technologies they require in your choice of path. For example, I ended up gaining a huge about of knowledge about Vue.js and Django in my time at Flatirons as well as what was required of me.&lt;/p&gt;

&lt;p&gt;Although the curriculum is much smaller, they go into a much greater degree of depth and you are normally spending almost eight hours a day on one very particular subject for weeks at a time to gain mastery. This means the learning and experience come much faster and sometimes more rewarding than at a college where some subjects are stretched out to multiple semesters through smaller classes.&lt;/p&gt;

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

&lt;p&gt;In terms of the curriculum, I am more of a fan of the boot camp system to learn to code. The reason being If you find exactly what type of field you would like to go into, having the means to only go into that single subject feels extremely challenging and rewarding compared to going through a large list of subjects. But if you don't know what kind of path you would like to take but just know you would like to get into the tech field, a college degree gets you a wide variety of knowledge on a large list of subjects and also gives you a lot more flexibility in your career choice in the end.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>webdev</category>
      <category>college</category>
    </item>
    <item>
      <title>How to Deploy a Ruby On Rails Backend to Heroku</title>
      <dc:creator>Kyle Petersen</dc:creator>
      <pubDate>Sun, 04 Oct 2020 05:36:15 +0000</pubDate>
      <link>https://forem.com/kpete2017/how-to-deploy-a-ruby-on-rails-backend-to-heroku-1ia0</link>
      <guid>https://forem.com/kpete2017/how-to-deploy-a-ruby-on-rails-backend-to-heroku-1ia0</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;Ruby on Rails for many years now has been an extremely popular and influential framework that allows a programmer to build up and deploy a REST API extremely quickly. With that in mind, many developers will choose to deploy using Heroku do to its simplicity and generous pricing for smaller projects.&lt;/p&gt;

&lt;h1&gt;
  
  
  Getting Started
&lt;/h1&gt;

&lt;p&gt;The first thing we are going to need is PostgreSQL as our database management system. This is Heroku's preferred database management system and Heroku will not work with Ruby on Rail's default sqlite3. Installation instructions for your operating system can be found &lt;a href="https://www.postgresql.org/download/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We also want to download and install the Heroku CLI which can be found &lt;a href="https://devcenter.heroku.com/articles/heroku-cli"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before we start getting Heroku set up in our project, we are going to need to make sure that our Ruby on Rails is using PostgreSQL as our database technology instead of its default sqlite3. If you have already built your backend around sqlite3 you can read about migrating it over to PostgreSQL &lt;a href="https://dev.to/torianne02/making-the-change-from-sqlite3-to-postgresql-ruby-on-rails-2m0p"&gt;here&lt;/a&gt;. Otherwise, if you are just starting a Ruby on Rails backend you can automatically configure it for PostgreSQL by adding the &lt;code&gt;--database=postgresql&lt;/code&gt; flag when creating your project like so &lt;code&gt;rails new project-name --api --database=postgresql&lt;/code&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Deploying our Backend
&lt;/h1&gt;

&lt;p&gt;Once your rails backend is ready to be deployed you are going to need to create a &lt;a href="https://signup.heroku.com/login"&gt;Heroku Account&lt;/a&gt;. Once finished we need to click on the "new" button in the top right corner of the web page and then click "create a new app" within the drop-down where it will then ask you to pick a name for the app. Name the app and then click "Create App"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JnmGbDSk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0bw3u3ul8z84swtbf4ld.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JnmGbDSk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0bw3u3ul8z84swtbf4ld.PNG" alt="Alt Text" width="719" height="305"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once your app is finished being created you will want to enter your Ruby on Rails directory and then run the command &lt;code&gt;heroku login&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LVzly8C5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2fhsdcfetzbw7usw49en.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LVzly8C5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2fhsdcfetzbw7usw49en.PNG" alt="Alt Text" width="807" height="529"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once logged into your Heroku account from your terminal you are going to run these commands in order.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git init&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;heroku git:remote -a &amp;lt;name of your project&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git add .&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git commit -am "any message you want"&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git push heroku master&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once this series of commands is finished, your code is now deployed up to Heroku. You can run any of your Rails command line commands as long as you preface it with &lt;code&gt;heroku run&lt;/code&gt;. For example, if we wanted to create our database within our Heroku server we would run &lt;code&gt;heroku run rake db:create&lt;/code&gt; or if we wanted to enter our console we could run &lt;code&gt;heroku run rails console&lt;/code&gt; from our command line.&lt;/p&gt;

&lt;p&gt;If you wanted to access the address for your newly deployed server you can click on the overview tab and click the open app button located in the top right corner of the webpage and it will take you to the hosted web address.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_AYwOdZR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4aqwd36higit9pol4e9i.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_AYwOdZR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4aqwd36higit9pol4e9i.PNG" alt="Alt Text" width="880" height="88"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>beginners</category>
      <category>rails</category>
    </item>
    <item>
      <title>How to deploy your Vue app to google firebase</title>
      <dc:creator>Kyle Petersen</dc:creator>
      <pubDate>Fri, 21 Aug 2020 19:04:04 +0000</pubDate>
      <link>https://forem.com/kpete2017/how-to-deploy-your-vue-app-to-google-firebase-p1l</link>
      <guid>https://forem.com/kpete2017/how-to-deploy-your-vue-app-to-google-firebase-p1l</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;Firebase is an extremely flexible and easy to use website hosting platform with a very generous free hosting tier. It is highly recommended for any beginners for hosting due to its pure simplicity to use and fast deployment.&lt;/p&gt;

&lt;h1&gt;
  
  
  Installation
&lt;/h1&gt;

&lt;p&gt;Before we begin we should download the Firebase CLI which allows us to quickly deploy our app from terminal&lt;/p&gt;

&lt;p&gt;Assuming we already have &lt;a href="https://nodejs.org/en/download/"&gt;Node.js&lt;/a&gt; installed and we already have a &lt;a href="https://vuejs.org/"&gt;Vue.js&lt;/a&gt; app we can deploy we can download the Firebase CLI with &lt;a href="https://www.npmjs.com/get-npm"&gt;NPM&lt;/a&gt; or node package manager. To download all you need to do is run &lt;code&gt;npm install -g firebase-tools&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now we need to create our firebase account. To do that navigate to &lt;a href="https://firebase.google.com/"&gt;The Google Firebase Website&lt;/a&gt; and create a new account.&lt;/p&gt;

&lt;p&gt;After your account has been created you need to login to firebase within your terminal. To do this run &lt;code&gt;firebase login&lt;/code&gt; at which point&lt;/p&gt;

&lt;p&gt;After you have logged into firebase you are now ready to deploy your project!&lt;/p&gt;

&lt;h1&gt;
  
  
  Deployment
&lt;/h1&gt;

&lt;p&gt;Before we start our firebase deployment we also need to run a production build of our app. From your app's main directory, run the command &lt;code&gt;npm run build&lt;/code&gt;. After a short load, you should see a new folder appear called "dist"&lt;/p&gt;

&lt;p&gt;To start we need to create a new project from the firebase website. From the "Your Firebase Projects" page on firebase go ahead and click "Add Project". Afterward, it will ask for a name and whether you would like to use Google analytics. While analytics is nice it's not normally needed for most small projects. After hitting "Create Project" there will be a short load you will be taken to your projects dashboard.&lt;/p&gt;

&lt;p&gt;On the left-hand side of the dashboard click on the button "Hosting" Than on the hosting page go ahead and click "Get Started"&lt;/p&gt;

&lt;p&gt;At this point, it will prompt you to install firebase CLI and login which we have already done. In your terminal from your main app directory go ahead and type &lt;code&gt;firebase init&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Within your projects, the main directory run &lt;code&gt;firebase init&lt;/code&gt; within your terminal. After you hit enter a screen with multiple options should appear. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Navigate to the option that says "Hosting", use your space key to select the option, and then hit enter.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--h-Dm8c25--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/vux4802fvugpbvpvc870.PNG" alt="Alt Text" width="880" height="359"&gt; &lt;/li&gt;
&lt;li&gt;On the next screen select the option "Use an existing project?".&lt;/li&gt;
&lt;li&gt;Afterwards it will ask you to select an existing project. You should choose the one you named earlier.&lt;/li&gt;
&lt;li&gt;After this, it will ask what you should make your public directory. The folder we created earlier named "dist" is what we will be using.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aatMBuhw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/821zlxknhnq0yr1tb33v.PNG" alt="Alt Text" width="632" height="114"&gt;
&lt;/li&gt;
&lt;li&gt;It will then ask if you would like to configure it as a single-page app. All this really does is route all URLs to the index of your app. If that is something you would prefer you can yes in this instance but for the most part its recommended to say no.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lLSn-ETu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rl4gs2sle46gryfrdfgq.PNG" alt="Alt Text" width="751" height="128"&gt;
*The next step will check if there is already an index.html and if you would like to overwrite it if so. It is highly recommended you say no as overwriting the default Vue index.html file could lead to other side effects.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--o1CY4L8X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9uw12fw8ecgjn5oldhao.PNG" alt="Alt Text" width="671" height="145"&gt;
*After this step your initialization is complete!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that initialization is complete all you need to do is run &lt;code&gt;firebase deploy&lt;/code&gt; and your all done! You can access your website through the URL that Google firebase provides you. If you would like to deploy any changes in the future you only need to run &lt;code&gt;npm run build&lt;/code&gt; and &lt;code&gt;firebase deploy&lt;/code&gt; again.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Make a Single Page App in Vue.js Part 2</title>
      <dc:creator>Kyle Petersen</dc:creator>
      <pubDate>Thu, 20 Aug 2020 03:52:31 +0000</pubDate>
      <link>https://forem.com/kpete2017/how-to-make-a-single-page-app-in-vue-js-part-2-1a50</link>
      <guid>https://forem.com/kpete2017/how-to-make-a-single-page-app-in-vue-js-part-2-1a50</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;In the first part, I explained how to get Vue.js running and how to edit the HelloWorld.vue component in order to make "Hello World!" show up on the screen. Now in part 2, I am going to go into a little bit more depth on Vue single file components as well as splitting up our hello worlds into two separate ones.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is a single file component?
&lt;/h1&gt;

&lt;p&gt;Quite simply, a single file component is where your HTML, CSS, and Javascript are all placed into a single file. This encourages building websites out of smaller "Components" that can act individually from each other making your code much more readable and organized.&lt;/p&gt;

&lt;h1&gt;
  
  
  Back to our app
&lt;/h1&gt;

&lt;p&gt;From our HelloWorld.vue file we should see everything nested into three separate tags. The first being &lt;code&gt;&amp;lt;template&amp;gt;&lt;/code&gt; the second being &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; and the third being &lt;code&gt;&amp;lt;style scoped&amp;gt;&lt;/code&gt;. Within our &lt;code&gt;&amp;lt;template&amp;gt;&lt;/code&gt; tag is housed all of our HTML code which will be the building blocks of our components, our &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag contains all of the Javascript for our component, and lastly our &lt;code&gt;&amp;lt;style scoped&amp;gt;&lt;/code&gt; tag contains all of our stylings. A quick note that the "scoped" after style indicates that this stylesheet will not affect other components. This allows us to name our HTML classes and Id's more confidently and legibly since we are not worried about side effects. From this file, all we are going to do is remove the word "World!" from "Hello World!".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--THzQE_KK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/hcz4vgmzpkjn65t35pxf.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--THzQE_KK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/hcz4vgmzpkjn65t35pxf.PNG" alt="Alt Text" width="597" height="611"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Create a new component
&lt;/h1&gt;

&lt;p&gt;To create a new component we are going to navigate to our /components folder and then add a new file called World.vue. Once here we should see a completely empty file. Type &lt;code&gt;&amp;lt;vue&amp;gt;&lt;/code&gt; within the text editor and hit the tab or enter key and it should auto-populate with a &lt;code&gt;&amp;lt;template&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; set of tags.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QJL-TJnX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0g1kzsr3kmjvr2q0nf7i.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QJL-TJnX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0g1kzsr3kmjvr2q0nf7i.PNG" alt="Alt Text" width="371" height="265"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After this, we should make sure to name our component. Just like in the HelloWorld.vue, we should type &lt;code&gt;name: "world"&lt;/code&gt; between the curly braces of the &lt;code&gt;export default { }&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;Back in our &lt;code&gt;&amp;lt;template&amp;gt;&lt;/code&gt; Tags, we should add a little bit of HTML. Just like our HelloWorld.vue file we should wrap everything in a div &lt;code&gt;&amp;lt;div class="world"&amp;gt;&lt;/code&gt;. Within that div, we should create an &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; tag that says "World!" like so &lt;code&gt;&amp;lt;h1&amp;gt;World!&amp;lt;/h1&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FOaELwee--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3swiyc5aj82h5r55a908.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FOaELwee--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3swiyc5aj82h5r55a908.PNG" alt="Alt Text" width="320" height="291"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Connecting Our Component
&lt;/h1&gt;

&lt;p&gt;You might have noticed by now that our component isn't displaying on the screen at the moment. Well, that's because we haven't told anything to mount it! Navigate back up to your app.vue file and it should look like this still.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Q1ENMm7q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/97b6kpqs9i4qih21ey6y.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Q1ENMm7q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/97b6kpqs9i4qih21ey6y.PNG" alt="Alt Text" width="489" height="557"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now to connect the components we need to import it first. Right below where it says &lt;code&gt;import HelloWorld from './components/HelloWorld.vue'&lt;/code&gt; you should type &lt;code&gt;import World from './components/World.vue'&lt;/code&gt;. After we have imported the file we need to tell Vue that it is a component. In an object called components: you should just see HelloWorld. You should add an apostrophe after HelloWorld than on the next line add "World". In the end it should look like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_k4B4SeG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5gfetoins3wtlvj4badx.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_k4B4SeG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5gfetoins3wtlvj4badx.PNG" alt="Alt Text" width="429" height="235"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The last thing we need to do is add our component to our &lt;code&gt;&amp;lt;template&amp;gt;&lt;/code&gt;. right below where it says &lt;code&gt;&amp;lt;HelloWorld msg="Welcome to Your Vue.js App"/&amp;gt;&lt;/code&gt; go ahead and type &lt;code&gt;&amp;lt;World/&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And tada! your just broke up your hello world into two components which are both being displayed!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How To Make a Simple Single Page App with Vue.js Part 1</title>
      <dc:creator>Kyle Petersen</dc:creator>
      <pubDate>Thu, 20 Aug 2020 02:57:03 +0000</pubDate>
      <link>https://forem.com/kpete2017/how-to-make-a-simple-single-page-app-with-vue-js-54ai</link>
      <guid>https://forem.com/kpete2017/how-to-make-a-simple-single-page-app-with-vue-js-54ai</guid>
      <description>&lt;h1&gt;
  
  
  Why Vue.js?
&lt;/h1&gt;

&lt;p&gt;The open-source Javascript framework Vue.js has been growing in popularity rapidly for quite some time now and for good reason. Vue has a multitude of features that adds huge quality of life that is not offered in other frameworks such as its minimal template syntax or its single-file components. It also offers a very low learning curve making it easy for anyone familiar with HTML, CSS, and Javascript!&lt;/p&gt;

&lt;h1&gt;
  
  
  What are we making?
&lt;/h1&gt;

&lt;p&gt;So today we are going to be making a simple hello world app with the Vue CLI and in part 2 we will be breaking it down into multiple components! But before we start, we are going to need to install a few things. &lt;/p&gt;

&lt;h1&gt;
  
  
  Installation
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt; Start by installing &lt;a href="https://nodejs.org/en/" rel="noopener noreferrer"&gt;Node.js&lt;/a&gt; with your appropriate operating system.+&lt;/li&gt;
&lt;li&gt;To make sure you are using node version 8.9 or above, run
&lt;code&gt;vue --version&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Then within our terminal, we need to run 
&lt;code&gt;npm install -g @vue/cli&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Annnnnd was all set on setting up the CLI! Now we get to create our app.&lt;/p&gt;

&lt;h1&gt;
  
  
  Creating our app
&lt;/h1&gt;

&lt;p&gt;In order to create a new app in the CLI we need to start by running the command &lt;code&gt;vue create hello-word&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;After running this you should see a few options&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%2F6xsvz2ikz3t7ggbw1kd4.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%2F6xsvz2ikz3t7ggbw1kd4.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From here we can decide whether we want to use preset features for vue, or if we would like to manually add or remove some features such as veux or vue-router. For now, though we can just use the defaults. In the terminal, you can select what items you want then hit Enter once finished.&lt;/p&gt;

&lt;p&gt;And after a long installation that it!&lt;/p&gt;

&lt;h1&gt;
  
  
  Running our app
&lt;/h1&gt;

&lt;p&gt;Once you change directories and open the hello-world app you should see a bit of code already laid out for you. In fact if you go ahead and type in your console&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;npm run serve&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 and navigate to &lt;a href="https://localhost8080" rel="noopener noreferrer"&gt;https://localhost8080&lt;/a&gt; you should be able to see a web-page!&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%2F7hbzxu104hswavxlzcpc.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%2F7hbzxu104hswavxlzcpc.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Congratulations you're running your own Vue page!&lt;/p&gt;

&lt;h1&gt;
  
  
  Creating Our Hello World
&lt;/h1&gt;

&lt;p&gt;Now back to your preferred text editor. The file structure of your app should look something like&lt;/p&gt;

&lt;p&gt;hello-word&lt;br&gt;
|-node_modules&lt;br&gt;
|-public&lt;br&gt;
|-src&lt;/p&gt;

&lt;p&gt;For the moment, the only folder you should worry about is the src. Within the src folder, it should look something like&lt;/p&gt;

&lt;p&gt;src&lt;br&gt;
|-assets&lt;br&gt;
|      -logo.png&lt;br&gt;
|-components&lt;br&gt;
|      -HelloWorld.vue&lt;br&gt;
|-app.js&lt;br&gt;
|-main.js&lt;/p&gt;

&lt;p&gt;Main.js is where our Vue app is originally created at the top level. This file calls upon the App.vue component which then calls upon the HelloWorld.vue component. If we click on the HelloWorld.vue file we should see a whole lot of code. This code is whats making up localhost:8080 at the moment. At the top of the page should be a tag name &lt;code&gt;&amp;lt;template&amp;gt;&lt;/code&gt;, right below that should be a tag named &lt;code&gt;&amp;lt;div class="hello"&amp;gt;&lt;/code&gt;. Everything between the tag &lt;code&gt;&amp;lt;div class="hello"&amp;gt;&lt;/code&gt; and its closing tag &lt;code&gt;&amp;lt;/div&amp;gt;&lt;/code&gt; you should be delete. If all is well, we should end up with a blank white web-page with a Vue logo at the center when we navigate back to localhost:8080.Now between the &lt;/p&gt; and the  enter &lt;code&gt;&amp;lt;h1&amp;gt;Hello World!&amp;lt;/h1&amp;gt;&lt;/code&gt;. 

&lt;p&gt;After that you should see this screen:&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%2Fyd9glxxv3lrdsgu2nqp6.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%2Fyd9glxxv3lrdsgu2nqp6.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Congrats! You have just printed hello world to the screen in vue.js! For part two I am going to show you how to break your Vue project into multiple components.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>vue</category>
    </item>
  </channel>
</rss>
