<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Zak Laughton</title>
    <description>The latest articles on DEV Community by Zak Laughton (@zaklaughton).</description>
    <link>https://dev.to/zaklaughton</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%2F237830%2F22c32876-df67-4ea0-b725-4ea5e61938c5.jpg</url>
      <title>DEV Community: Zak Laughton</title>
      <link>https://dev.to/zaklaughton</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zaklaughton"/>
    <language>en</language>
    <item>
      <title>Zak's Top 5 Habits for Success</title>
      <dc:creator>Zak Laughton</dc:creator>
      <pubDate>Sat, 30 Jul 2022 19:28:20 +0000</pubDate>
      <link>https://dev.to/zaklaughton/zaks-top-5-habits-for-success-26d7</link>
      <guid>https://dev.to/zaklaughton/zaks-top-5-habits-for-success-26d7</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;I recently wrote a letter to my brothers, who were graduating high school, outlining the 5 habits I've found to be the most important for succeeding in careers, relationships, and life. It ended up taking a while to write, and I thought others might find it useful, so I've decided to share with a more public audience. Enjoy!&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hey [brother],&lt;/p&gt;

&lt;p&gt;Congrats on graduating! Along with some cash from [wife] and me, I wanted to share a few things I've learned that have helped me in my career. Since graduating high school, I've found there are a few simple skills and mindsets that will put you miles ahead of others without too much effort. These are all things I wish I would have known when graduating high school.&lt;/p&gt;

&lt;p&gt;But you're graduating and probably getting lots of random advice from family members about how to live your life and what to do. So why listen to me?&lt;/p&gt;

&lt;p&gt;I've done extremely well over the past decade. Since starting in the software industry, I’ve consistently received the highest performance reviews on my teams at work, which has led to a significant promotion or pay increase every year. I am being paid significantly more today than I was 7 years ago, and it’s helped us pay off $100,000 in debt and live a happy, comfortable lifestyle.&lt;/p&gt;

&lt;p&gt;I’m not saying any of this to brag, but to emphasize that I’ve found successful, reliable methods that continue to advance my career year after year. The principles I’m describing in this letter have helped me succeed in every situation as I rose up through &lt;a href="https://www.linkedin.com/in/zaklaughton/"&gt;4 different roles on 5 different teams at 2 different companies&lt;/a&gt;. I genuinely think the advice in this letter will help you become a more successful person in your career and in your personal life. This is the first time I’ve shared these collective tips, so I hope you find them useful!&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Seek first to understand, then to be understood
&lt;/h2&gt;

&lt;p&gt;If you only take one thing from this letter, make it this one: &lt;strong&gt;Seek first to understand, then to be understood&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In your life, you will come across many people and situations you disagree with. Your boss will make seemingly dumb decisions, your significant other will get upset about things that seem unimportant to you, you'll meet people with completely different political and religious views that sound absurd to you, and you'll have to follow processes at work that look like they were created by a complete idiot. It's natural to immediately write off contradicting opinions to your own as "wrong" or "dumb". Do not do this. Ever. Instead, get curious.&lt;/p&gt;

&lt;p&gt;Everyone has their own opinions and motivations, and for the most part, nobody is actively trying to make bad decisions. That dumb decision your boss made might have been the best thing they could do, given requirements you didn't know about from their boss. That thing your significant other is upset about might be related to a deeper concern about your relationship. That person who has crazy political views might have had years of indoctrination, or they might have some information or perspective you don't have. That dumb process at work might have come from years of reworking former “smarter” processes that have failed in the past. In any case, you are going to have a hard time making any of these situations better without first understanding the reasoning behind them.&lt;/p&gt;

&lt;p&gt;When you come across a situation that makes you unhappy or someone you disagree with, get curious and ask questions. What led to things being this way? Why do people think this is a good idea? Do you understand why they think that or how they got to their conclusions? Ask specific questions and get specific answers. As long as you're coming from a place of genuine curiosity (not criticism), people will generally be more than willing to explain the context that you don’t have. And always keep in mind that no matter how confident you are about something, you could be wrong. The only way you're going to find out if you're wrong (or have the best information about why you're right) is to find out more from the people who disagree with you.&lt;/p&gt;

&lt;p&gt;When you take time to listen to what other people have to say before inserting your own opinions, you also build trust and understanding. Active listening is a huge influencer, and people will be much more willing to listen to what you have to say if you've listened to them first. And by listening first, you'll also have better context and information to make sound decisions going forward.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Assume positive intent
&lt;/h2&gt;

&lt;p&gt;This goes hand-in-hand with seeking first to understand. As you are seeking to understand others, it's important to not assume malice, and instead assume positive intent. One of the biggest blockers I've seen to progress and communication is when people assume the other person in a relationship (professional or otherwise) is intentionally screwing them over. When you don't get what you want, it can be easy to take it personally and assume the other person is targeting you or just being lazy. &lt;strong&gt;This is a toxic mindset that creates unnecessary stress and stops all useful conversations.&lt;/strong&gt; Why even try to fix the situation or find out more when you “know” the other side is doing it on purpose or isn't willing to change?&lt;/p&gt;

&lt;p&gt;Even if someone is trying to take advantage of you, the only productive way to continue a conversation is to assume they’re doing their best to work with you. This gives you a way to talk about why you're upset with their actions or ask them why things turned out differently than you expected. And if they continually act this way, it gives you a way to talk about it and plan for further contradictory behavior in the future.&lt;/p&gt;

&lt;p&gt;Too many people assume bad intent and never follow up, which halts all progress and leaves them in a bitter state. I've seen days, weeks, and months wasted on projects all because people just didn't want to address a difference in expectations with someone. In most cases, it was just a lack of understanding that could have been cleared up with a simple question.&lt;/p&gt;

&lt;p&gt;Assuming positive intent is great for your mental health, too. When I started practicing this several years ago, I realized how many small pointless grudges I was holding and how nice it was to let them go. For years I'd get upset when someone cut me off in traffic, or when a client wouldn't give me all the information I asked for, or when someone on my team at work didn't complete a task. All these unaddressed negative thoughts built up and added unneeded stress to my life with absolutely no benefits or promise of resolution. Assuming positive intent allows you to focus on the facts and not waste mental energy on negative thoughts that serve no purpose other than to make you madder. It forces you to actually think of solutions rather than pointing fingers and giving up.&lt;/p&gt;

&lt;p&gt;On the opposite end of this, beware the chronic complainers. At most jobs, you will find negative people who make a habit of assuming bad intent. You'll often find them in groups, talking about how horrible everything is, how nothing will change, and how they're victims of their circumstances. In the short term, it's much easier to sit and complain like this. In the long term, these people find themselves stuck, unhappy, and unable to make any progress until they quit and find a new job where they find new things to complain about. Stay away from these types of people and mindsets if you want to grow and not be miserable. There are healthier ways to deal with stress.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Have a system for getting things done
&lt;/h2&gt;

&lt;p&gt;You'd be amazed how many professionals far into their careers cannot reliably complete simple routine tasks. Too many people overcommit and don't keep track of their obligations, leaving their boss and coworkers constantly following up with them.&lt;/p&gt;

&lt;p&gt;Know the minimum requirements of your job, and do them. If you have a weekly timesheet you need to submit, or a monthly report you have to do, make sure you have a system in place to remind you to get these done. These are probably some of the easiest and least important responsibilities you have, but not doing them will lose trust with your colleagues quickly. Being able to regularly complete simple routine tasks is an easy way to show you're reliable when compared to your coworkers who have to constantly be reminded by your manager every week.&lt;/p&gt;

&lt;p&gt;Having a system to track everything you need to do also gives you a way to take your mind off unimportant tasks while focusing on the more important ones. Set up systems that make it easy to do the minimum requirements for the parts of your job you don't enjoy so you can use your energy to excel at the parts you actually do enjoy.&lt;/p&gt;

&lt;p&gt;For effective tips in setting up a system for tracking tasks, I highly recommend reading "Getting Things Done" (or listening to the audiobook). This is the very first career advice book I read. It changed the way I thought about work, and I attribute a lot of my career growth to practices I learned from that book.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Have a budget
&lt;/h2&gt;

&lt;p&gt;It's important to have a budget so you can know where your money is going and plan for unexpected expenses. This becomes especially important if you're paying off debt such as student and car loans. You should know how much money you have compared to how much debt you have, and you should make sure that your net worth continues to trend upward. This is very difficult to track without a budget.&lt;/p&gt;

&lt;p&gt;A budget doesn't restrict the money you spend; it gives you a realistic picture of your spending. As your bank account grows, you need to know how much of that money you need to hold onto to pay for infrequent, expected expenses like replacing car tires or unexpected expenses like emergency medical procedures. Having a realistic view of your true expenses will give you a better idea of how much money you actually have and how much you can comfortably spend on more fun, frivolous things. Living within your means also makes it easier to focus on building your career, skills, and network without being hyperfocused on the size of your paycheck.&lt;/p&gt;

&lt;p&gt;[Wife] and I have tracked every single expense we've made over the past 10 years. We've gone from more than $100,000 in debt to having a higher net worth than most people our age, and our budget has guided us in keeping in the right direction every step of the way.&lt;/p&gt;

&lt;p&gt;There are a lot of budgeting programs out there, and you should pick one that you'll use and that works for you. I personally recommend a program called &lt;a href="https://ynab.com/referral/?ref=HO-GPPf79Q0xSOKg"&gt;YNAB&lt;/a&gt; (short for "You Need A Budget"). They offer a free month and have a lot of great online training to help you manage your money.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Read
&lt;/h2&gt;

&lt;p&gt;One of the more surprising tools I’ve used to improve myself and advance in my career is books. When I graduated high school, I had heard of popular self-help books and career advice books, but I didn't think they'd be useful. I figured they were just feel-good fluff motivational books without much to offer. It wasn't until I read "Getting Things Done" early in my career that I realized how helpful books can be in giving advice for navigating life, relationships, and communicating with others. Most of what's in this letter is a combination of what I've learned from these books and found to be the most useful. Today, I always have an e-book or audiobook that I'm reading or listening to, and often return to my favorites for more insight. &lt;/p&gt;

&lt;p&gt;Here are the top books I’ve read so far that have had the biggest impact on me:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://amzn.to/3BmFmUd"&gt;Getting Things Done&lt;/a&gt;&lt;/strong&gt; – The first productivity book I read, which shapes a lot about how I live my life and succeed in my career today&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://amzn.to/3oAZ5b9"&gt;The 7 Habits of Highly Effective People&lt;/a&gt;&lt;/strong&gt; – Great advice on how to work effectively and handle relationships&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://amzn.to/3blq0V8"&gt;How to Win Friends and Influence People in the Digital Age&lt;/a&gt;&lt;/strong&gt; – A modernized version of the classic &lt;a href="https://amzn.to/3bdahHT"&gt;"How to Win Friends and Influence People"&lt;/a&gt;, this book gives a lot of surprising insight into building relationships with others. This changed my way of thinking about the effort needed to get to know people, helping me realize that building relationships is mostly just being interested in other people.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://amzn.to/3cOQU8y"&gt;Radical Candor&lt;/a&gt;&lt;/strong&gt; – Great advice on how to talk to people and have difficult conversations&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://amzn.to/3cPQYVu"&gt;The Subtle Art of Not Giving a F*ck&lt;/a&gt;&lt;/strong&gt; – This book gives a good perspective on how to live life a little more stress-free and focus on the things that matter.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://amzn.to/3Bo6e68"&gt;Getting to Yes&lt;/a&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;a href="https://amzn.to/3bc98Aq"&gt;Never Split the Difference&lt;/a&gt;&lt;/strong&gt; – These are two great books about negotiation that give tips for handling tough conversations in all parts of your life (not just for negotiating purchases and business deals).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://amzn.to/3BqI4bd"&gt;Atomic Habits&lt;/a&gt;&lt;/strong&gt; – Nobody becomes a success overnight. Most successful people got to where they are by setting up systems and making small, incremental improvements every day over an extended period of time. Atomic Habits is a great guide to setting yourself up for success with focused habits.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://amzn.to/3Q0DeFF"&gt;Never Eat Alone&lt;/a&gt;&lt;/strong&gt; – A helpful book about making connections with others and the powerful impact a good network can have on your career.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope some of this advice helps! You're at an exciting point at the start of your adult life where you can head in any direction. If you focus on getting a little better each day in your career and relationships, you can have a happy, successful life. Feel free to text me any time for life advice, career advice, or whatever. Congrats, again!&lt;/p&gt;

&lt;p&gt;—Zak&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>career</category>
      <category>softskills</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Getting your first website on the internet is easier than you think!</title>
      <dc:creator>Zak Laughton</dc:creator>
      <pubDate>Mon, 27 Apr 2020 14:23:30 +0000</pubDate>
      <link>https://dev.to/zaklaughton/getting-your-first-website-on-the-internet-is-easier-than-you-think-3452</link>
      <guid>https://dev.to/zaklaughton/getting-your-first-website-on-the-internet-is-easier-than-you-think-3452</guid>
      <description>&lt;p&gt;Just before writing this article, I built a full website and published it online, &lt;strong&gt;and it only took 5 minutes!!!&lt;/strong&gt; You can see the full site in all its glory here: &lt;a href="https://zaklaughton.github.io/im-on-the-internet/"&gt;https://zaklaughton.github.io/im-on-the-internet/&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Y61eGah1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ecq74rycd8hqvcj5pjdr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y61eGah1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ecq74rycd8hqvcj5pjdr.png" alt="screenshot of website"&gt;&lt;/a&gt;&lt;/p&gt;
Wow!



&lt;p&gt;Okay, okay, so it's not the most impressive site (see all 3 lines of code in the repo &lt;a href="https://github.com/ZakLaughton/im-on-the-internet"&gt;here&lt;/a&gt;), but it &lt;em&gt;was&lt;/em&gt; incredibly easy to put on the internet.&lt;/p&gt;

&lt;p&gt;When I started learning web development, I thought getting my work online would be complicated. I pushed off figuring it out how to do it for way too long. It turns out, as long as you have an HTML file and a git repository, you can publish your site within minutes — you can even get a custom URL!&lt;/p&gt;

&lt;p&gt;(This article assumes a basic understanding of git to push to a remote repository. If you're a new web developer unfamiliar with git, you'll need to learn it! Check out some of the training resources &lt;a href="https://try.github.io/"&gt;here&lt;/a&gt;).&lt;/p&gt;

&lt;h1&gt;
  
  
  GitHub pages
&lt;/h1&gt;

&lt;h3&gt;
  
  
  Static files with GitHub Pages
&lt;/h3&gt;

&lt;p&gt;My amazing "I'm on the internet" site above was posted online using &lt;a href="https://pages.github.com/"&gt;Github pages&lt;/a&gt;. Github pages is the simplest way to get your repository up on the internet. It's easy, free, and comes built-in with every repository on GitHub.&lt;/p&gt;

&lt;p&gt;GitHub pages simply finds an &lt;code&gt;index.html&lt;/code&gt; file in the root of your repository, and makes it available at a URL. As long as your repository has an &lt;code&gt;index.html&lt;/code&gt; file you can open in a browser on your own computer, then this setup will work for you!&lt;/p&gt;

&lt;p&gt;To enable:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to your repository on GitHub&lt;/li&gt;
&lt;li&gt;Click "Settings"&lt;/li&gt;
&lt;li&gt;Under &lt;em&gt;GitHub Pages&lt;/em&gt;, select &lt;em&gt;master branch&lt;/em&gt; as the source.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EiFQywVv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/517j779j3716txtt66kg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EiFQywVv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/517j779j3716txtt66kg.png" alt="screenshot of GitHub settings"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's it! Github will provide you with a URL that you or anyone can use to access your site, and the site will &lt;em&gt;automatically update&lt;/em&gt; whenever you update your repository. Pretty cool!&lt;/p&gt;

&lt;p&gt;💡&lt;a href="https://guides.github.com/features/pages/"&gt;Step-by-step guide to getting started with GitHub pages&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Framework sites with GitHub Pages
&lt;/h3&gt;

&lt;p&gt;If you're using a framework such as &lt;a href="https://reactjs.org/"&gt;React&lt;/a&gt; to build your site, you probably don't have an index.html just laying out there to be served up. These types of frameworks typically require you to &lt;strong&gt;build&lt;/strong&gt; the site — this just means running a command to take all your files written for your framework and turn them into a simple "index.html" site that browsers will understand. Most often, these end up in some sort of "/build" folder.&lt;/p&gt;

&lt;p&gt;For GitHub Pages to use this page, you'll need to build the site, put the built site on a new branch, and point Github Pages to the "build" branch. It's a few extra steps, but still should still be relatively quick to get your site online. There are also some great tools out there to automate this for you.&lt;/p&gt;

&lt;p&gt;💡&lt;a href="https://gist.github.com/cobyism/4730490"&gt;Step-by-step guide for publishing a subfolder to GitHub pages&lt;/a&gt;&lt;br&gt;
💡If you're using React, check out &lt;a href="https://github.com/gitname/react-gh-pages"&gt;react-gh-pages&lt;/a&gt;&lt;br&gt;
💡An example of a branch built in one of my projects from React to serve a webpage: &lt;a href="https://github.com/ZakLaughton/map-project/tree/gh-pages"&gt;https://github.com/ZakLaughton/map-project/tree/gh-pages&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Custom URL
&lt;/h1&gt;

&lt;p&gt;So what if you don't like having "github.io" in the URL and want to serve your GitHub pages site at your own custom domain name? Turns out, that's pretty easy too! As general steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Buy a domain name from a domain name provider (typically costs around $12/year).&lt;/li&gt;
&lt;li&gt;Update the domain name system (DNS) configuration with the provider to point to GitHub.&lt;/li&gt;
&lt;li&gt;Update the repository settings on GitHub to point to your custom URL.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There are many domain name providers out there, and I recommend doing some research to figure out what works best for you. Personally, I like &lt;a href="https://domains.google.com/"&gt;Google Domains&lt;/a&gt; for its low prices and intuitive interface.&lt;/p&gt;

&lt;p&gt;Once you purchase the domain name, just update the DNS settings as described in the &lt;a href="https://help.github.com/en/github/working-with-github-pages/configuring-a-custom-domain-for-your-github-pages-site"&gt;GitHub Pages documentation&lt;/a&gt;. Here are the settings for &lt;code&gt;youneedtocalmdown.fyi&lt;/code&gt;, which direct both &lt;a href="https://youneedtocalmdown.fyi"&gt;youneedtocalmdown.fyi&lt;/a&gt; and &lt;a href="https://www.youneedtocalmdown.fyi"&gt;&lt;/a&gt;&lt;a href="http://www.youneedtocalmdown.fyi"&gt;www.youneedtocalmdown.fyi&lt;/a&gt; to the same site:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WDI3QKQY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8zy5javes69skn0ipl8m.png" class="article-body-image-wrapper"&gt;&lt;img width="70%" src="https://res.cloudinary.com/practicaldev/image/fetch/s--WDI3QKQY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8zy5javes69skn0ipl8m.png" alt="DNS configuration screenshot"&gt;&lt;/a&gt;&lt;/p&gt;
DNS settings in Google domains. (Be sure to consult the GitHub docs for the most up-to-date address to use)



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wfavJ2P2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rhe1rfyuy8jeoaacww5f.png" class="article-body-image-wrapper"&gt;&lt;img width="70%" src="https://res.cloudinary.com/practicaldev/image/fetch/s--wfavJ2P2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rhe1rfyuy8jeoaacww5f.png" alt="Github settings"&gt;&lt;/a&gt;&lt;/p&gt;
Corresponding GitHub Pages settings on the repository



&lt;p&gt;💡&lt;a href="https://dev.to/trentyang/how-to-setup-google-domain-for-github-pages-1p58"&gt;How to setup Google Domain for GitHub pages&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Using subdomains
&lt;/h2&gt;

&lt;p&gt;$12/year for a domain name is pretty cheap, but this can get expensive as you start buying more. For many of your personal projects, you probably just want to host them on a subdomain on your site. You can do this by adding &lt;code&gt;CNAME&lt;/code&gt; entries into your DNS settings.&lt;/p&gt;

&lt;p&gt;Here's the DNS settings which direct to &lt;code&gt;zaklaughton.dev&lt;/code&gt;, along with all the GitHub repositories with GitHub Pages settings configured for &lt;a href="https://crossy.zaklaughton.dev"&gt;crossy.zaklaughton.dev&lt;/a&gt;, &lt;a href="https://map.zaklaughton.dev"&gt;map.zaklaughton.dev&lt;/a&gt;, &lt;a href="https://memory.zaklaughton.dev"&gt;memory.zaklaughton.dev&lt;/a&gt;, &lt;a href="https://minesweeper.zaklaughton.dev"&gt;minesweeper.zaklaughton.dev&lt;/a&gt;, and &lt;a href="https://myreads.zaklaughton.dev"&gt;myreads.zaklaughton.dev&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--t-f9g4a4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/679f10a0xc8w2br8k6q9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--t-f9g4a4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/679f10a0xc8w2br8k6q9.png" alt="DNS settings screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What if my site needs a server?
&lt;/h1&gt;

&lt;p&gt;In building web apps, you may get to a point where you do need a server to help serve the data on the page, such as with a &lt;a href="https://careerfoundry.com/en/blog/web-development/whats-the-difference-between-frontend-and-backend/"&gt;back-end server&lt;/a&gt; or a site that is &lt;a href="https://www.clariontech.com/blog/server-side-rendering-vs.-client-side-rendering"&gt;server-side rendered&lt;/a&gt;. While this isn't possible with GitHub pages, luckily there are sites that make it easy to host and run this server-side code, too! Both &lt;a href="https://www.netlify.com/"&gt;Netlify&lt;/a&gt; and &lt;a href="https://www.heroku.com/"&gt;Heroku&lt;/a&gt; are some of the more popular options.&lt;/p&gt;

&lt;p&gt;The finer details are outside the scope of this article, but know that there are also server-side options are out there to automate the deployment process from a git repository.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples&lt;/strong&gt;&lt;br&gt;
🌐 &lt;a href="https://flattenthecurve.zaklaughton.dev"&gt;flattenthecurve.zaklaughton.dev&lt;/a&gt; (&lt;a href="https://github.com/ZakLaughton/flatten-the-curve"&gt;repo&lt;/a&gt;) — Server-side rendered site (using &lt;a href="https://www.gatsbyjs.org/"&gt;Gatsby&lt;/a&gt;). Automatically builds and deploys the site when the GitHub master branch updates.&lt;br&gt;
🌐 &lt;a href="https://survivorstats.com"&gt;survivorstats.com&lt;/a&gt; (&lt;a href="https://github.com/ZakLaughton/survivor-stats"&gt;repo&lt;/a&gt;) — Front end is hosted on netlify. Back end (responsible for fetching database data) is hosted on Heroku. The back end is updated with simple commands from the &lt;a href="https://devcenter.heroku.com/articles/heroku-cli"&gt;Heroku CLI&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;p&gt;Putting your sites on the internet is a great way to share your work, and it's quick and easy to do! There's no need to wait to share your projects with the world.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;a href="https://pages.github.com/"&gt;GitHub Pages&lt;/a&gt; to make the sites in your GitHub repos public.&lt;/li&gt;
&lt;li&gt;For a custom URL, Set up a custom domain with a service like &lt;a href="https://domains.google.com"&gt;Google domains&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Use hosting services such as &lt;a href="https://www.netlify.com/"&gt;Netlify&lt;/a&gt; and &lt;a href="https://www.heroku.com/"&gt;Heroku&lt;/a&gt; if you require any server-side code.&lt;/li&gt;
&lt;/ul&gt;





&lt;center&gt;&lt;em&gt;Did you find this this article useful? Feel free to follow my profile below or &lt;a href="https://twitter.com/ZakLaughton"&gt;follow me on Twitter&lt;/a&gt; for more developer tips and article announcements!&lt;/em&gt;&lt;/center&gt;





</description>
      <category>webdev</category>
      <category>git</category>
      <category>codenewbie</category>
      <category>github</category>
    </item>
    <item>
      <title>Git deep-dive: "git init"</title>
      <dc:creator>Zak Laughton</dc:creator>
      <pubDate>Mon, 09 Mar 2020 04:50:31 +0000</pubDate>
      <link>https://dev.to/zaklaughton/git-deep-dive-git-init-2kg8</link>
      <guid>https://dev.to/zaklaughton/git-deep-dive-git-init-2kg8</guid>
      <description>&lt;p&gt;This article kicks off a multi-part series taking a closer look at the common parts of git we often take for granted.&lt;/p&gt;

&lt;p&gt;And what better way to start the series than with the command that starts all git repositories: &lt;code&gt;git init&lt;/code&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  What you might know
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;git init&lt;/code&gt; starts a new repository! You want source control in Git? Just run the command &lt;code&gt;git init&lt;/code&gt; and BAM!– that directory is now a git repository.&lt;/p&gt;

&lt;p&gt;Here's what it looks like in action:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wB4epkrg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9omg3gta1we59p7qhj08.gif" class="article-body-image-wrapper"&gt;&lt;img alt="git init in terminal demo" src="https://res.cloudinary.com/practicaldev/image/fetch/s--wB4epkrg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9omg3gta1we59p7qhj08.gif"&gt;&lt;/a&gt;Git commands such as &lt;code&gt;git status&lt;/code&gt; won't work in a directory until we initialize the git repository&lt;/p&gt;

&lt;p&gt;Once this is done, you can do all the cool things you do in git, such as &lt;code&gt;add&lt;/code&gt;, &lt;code&gt;commit&lt;/code&gt;, &lt;code&gt;merge&lt;/code&gt;, and more!...But those commands are for another article. We're here to focus a little more on the usage of &lt;code&gt;git init&lt;/code&gt;. Let's take a closer look...&lt;/p&gt;

&lt;h1&gt;
  
  
  What you might not know
&lt;/h1&gt;

&lt;h2&gt;
  
  
  💡 How the repository is initialized
&lt;/h2&gt;

&lt;p&gt;What is &lt;code&gt;git init&lt;/code&gt; actually doing when it initializes a repository? When you run the command, it creates a hidden directory called &lt;code&gt;.git&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Y-ilqOlG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/87q2je7s6xc1lii3f811.png" class="article-body-image-wrapper"&gt;&lt;img alt="screenshot of git init creating .git directory" src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y-ilqOlG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/87q2je7s6xc1lii3f811.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.git/&lt;/code&gt; contains all the behind-the-scenes data that makes git source control tick. All the branch information, past changes, current status, and more is all held here. Here's what the contents of that directory look like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--olquUbvt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5e3eueo9h2alh2i2i54s.png" class="article-body-image-wrapper"&gt;&lt;img alt="Screenshot of .git files and folders" src="https://res.cloudinary.com/practicaldev/image/fetch/s--olquUbvt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5e3eueo9h2alh2i2i54s.png" width="350px"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We aren't going to go through what each directory and file does here. Most of it isn't human-readable, and is only intended to be interacted with using Git. Just know that this &lt;code&gt;.git/&lt;/code&gt; sub-directory structure (or most of it) is required for git to do its thing.&lt;/p&gt;

&lt;p&gt;If you wanted, you could even manually create &lt;code&gt;.git/&lt;/code&gt; and all its contents, and git would still recognize it as a repository (Try it out if you have some free time! Which files are required? Which aren't?). This also means if you delete the &lt;code&gt;.git&lt;/code&gt; directory on an existing repository, all your branches and git history will be deleted as well. This can actually be useful if you're &lt;em&gt;very early&lt;/em&gt; in a project and decide you want to re-start a repository to initialize from your current working files. Just &lt;code&gt;rm -rf .git&lt;/code&gt; and &lt;code&gt;git init&lt;/code&gt; all over again.&lt;/p&gt;

&lt;h2&gt;
  
  
  💡 ALL repository data is stored in &lt;code&gt;.git/&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;We often think about git storing historical data, while your working directory (everything outside &lt;code&gt;.git/&lt;/code&gt;) has the current files. It's important to remember that Git, or more specifically: the &lt;code&gt;.git&lt;/code&gt; directory, has &lt;em&gt;all&lt;/em&gt; the data — including the most recent committed changes. In fact, you can even &lt;code&gt;git clone&lt;/code&gt; directly from the &lt;code&gt;.git&lt;/code&gt; directory, just like you would from a remote repository!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xkXznE2c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zfet2so31fzri16x22y4.png" class="article-body-image-wrapper"&gt;&lt;img alt="Original tree" src="https://res.cloudinary.com/practicaldev/image/fetch/s--xkXznE2c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zfet2so31fzri16x22y4.png"&gt;&lt;/a&gt;Now there are two of them!&lt;/p&gt;

&lt;h2&gt;
  
  
  💡 Create a "remote" repository with &lt;code&gt;--bare&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Did you know you can actually &lt;code&gt;push&lt;/code&gt; to and &lt;code&gt;pull&lt;/code&gt; from your local working repository? However, you might run into some issues. Watch what happens when we try to push the &lt;code&gt;master&lt;/code&gt; branch to a local working repository where &lt;code&gt;master&lt;/code&gt; is also checked out:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KEPxjv7P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/y3cevfg8c44wi3cqz9nq.png" class="article-body-image-wrapper"&gt;&lt;img alt="git error" src="https://res.cloudinary.com/practicaldev/image/fetch/s--KEPxjv7P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/y3cevfg8c44wi3cqz9nq.png"&gt;&lt;/a&gt;Git says "NO!"&lt;/p&gt;

&lt;p&gt;This is why you'll typically push and pull from a remote repository instead of from someone else's working repository. Most often, this remote repository setup is handled through a git repo service such as &lt;a href="https://bitbucket.org/product/"&gt;Bitbucket&lt;/a&gt; or &lt;a href="https://github.com/"&gt;GitHub&lt;/a&gt;, but if you wanted to set up your own, you'd use the &lt;code&gt;--bare&lt;/code&gt; flag:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aNQ8xYSu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/e4jd12tpisvayvbc6m0m.png" class="article-body-image-wrapper"&gt;&lt;img alt="--bare flag demo" src="https://res.cloudinary.com/practicaldev/image/fetch/s--aNQ8xYSu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/e4jd12tpisvayvbc6m0m.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Recognize those files and directories? That's everything we saw before in the hidden &lt;code&gt;.git&lt;/code&gt; repository, except now they aren't covered by a hidden folder! Yes, they're...&lt;em&gt;naked&lt;/em&gt;! 😮 So it shouldn't be surprising that this is known as a "bare repository". With a naked – um, I mean – &lt;em&gt;bare&lt;/em&gt; repository, you're essentially telling git, "Nobody's working here. Just store the data, and let users push and pull from it."&lt;/p&gt;

&lt;p&gt;Since nobody's working here, you don't really need anything outside the &lt;code&gt;.git&lt;/code&gt; directory. And if you don't need anything outside the &lt;code&gt;.git&lt;/code&gt; directory, why not just put all the &lt;code&gt;.git&lt;/code&gt; contents at the top level?&lt;/p&gt;

&lt;h2&gt;
  
  
  💡 Shhhhhh
&lt;/h2&gt;

&lt;p&gt;And finally...Is your &lt;code&gt;git init&lt;/code&gt; making TOO MUCH NOISE???&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OLOBdbpF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xlfzlgcex5v1c71q3rd6.png" class="article-body-image-wrapper"&gt;&lt;img alt="screenshot of git init" src="https://res.cloudinary.com/practicaldev/image/fetch/s--OLOBdbpF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xlfzlgcex5v1c71q3rd6.png"&gt;&lt;/a&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--x_Mm2SNx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/m19dcgtbt21jvkwxugd0.gif" class="article-body-image-wrapper"&gt;&lt;img alt="Man covering ears as cat walks by" src="https://res.cloudinary.com/practicaldev/image/fetch/s--x_Mm2SNx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/m19dcgtbt21jvkwxugd0.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Stop all that terrible noisy racket with the &lt;code&gt;-q&lt;/code&gt; or &lt;code&gt;--quiet&lt;/code&gt; flag:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bqhy26lF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/vu4vclm2ilaacdvmel7i.png" class="article-body-image-wrapper"&gt;&lt;img alt="screenshot of git init -q" src="https://res.cloudinary.com/practicaldev/image/fetch/s--bqhy26lF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/vu4vclm2ilaacdvmel7i.png"&gt;&lt;/a&gt;Finally, some peace and quiet!&lt;/p&gt;

&lt;h1&gt;
  
  
  Wrap-up
&lt;/h1&gt;

&lt;p&gt;I hope this has helped shine a light on how &lt;code&gt;git init&lt;/code&gt; works and how a repository is born. For further reading, you may want to check out:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://git-scm.com/docs/git-init"&gt;Official &lt;code&gt;git init&lt;/code&gt; documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.atlassian.com/git/tutorials/setting-up-a-repository/git-init"&gt;This &lt;code&gt;git init&lt;/code&gt; tutorial&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Stay tuned for the next article in the series where I cover the slightly-more-interesting command: &lt;code&gt;git add&lt;/code&gt;.&lt;/p&gt;





&lt;center&gt;&lt;em&gt;Did you find this this article useful? Feel free to follow my profile below or &lt;a href="https://twitter.com/ZakLaughton"&gt;follow me on Twitter&lt;/a&gt; for more developer tips and article announcements!&lt;/em&gt;&lt;/center&gt;





</description>
      <category>git</category>
      <category>codenewbie</category>
      <category>webdev</category>
      <category>productivity</category>
    </item>
    <item>
      <title>3 ways to time travel in Git to undo destructive mistakes</title>
      <dc:creator>Zak Laughton</dc:creator>
      <pubDate>Thu, 27 Feb 2020 13:35:02 +0000</pubDate>
      <link>https://dev.to/zaklaughton/3-ways-to-time-travel-in-git-to-undo-destructive-mistakes-inm</link>
      <guid>https://dev.to/zaklaughton/3-ways-to-time-travel-in-git-to-undo-destructive-mistakes-inm</guid>
      <description>&lt;p&gt;Raise your hand if you can relate:&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1232412585397571584-502" src="https://platform.twitter.com/embed/Tweet.html?id=1232412585397571584"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1232412585397571584-502');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1232412585397571584&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;🙋🙋🙋🙋🙋&lt;/p&gt;

&lt;p&gt;We've all been there! It's easy to do a well-meaning &lt;code&gt;git rebase&lt;/code&gt; or &lt;code&gt;git reset&lt;/code&gt; only to find everything broken afterwards. Then, since your changes &lt;a href="https://www.atlassian.com/git/tutorials/rewriting-history" rel="noopener noreferrer"&gt;rewrote history&lt;/a&gt;, the only way to go back is to delete everything and re-clone the repository to start over again. I used to do this all the time!&lt;/p&gt;

&lt;p&gt;But what if I told you there was a better way? What if you could &lt;em&gt;time travel&lt;/em&gt; back to a point before you did those destructive changes without deleting anything? It turns out, git has built-in tools for this such as &lt;code&gt;reflog&lt;/code&gt;, &lt;code&gt;ORIG_HEAD&lt;/code&gt;, and &lt;code&gt;gitrevisions&lt;/code&gt;, and they're surprisingly easy to use!&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%2Fn5343e32u8nelyqvm1a4.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%2Fn5343e32u8nelyqvm1a4.png" alt="Back to the Future screenshot with caption "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this article, I'll show you how to use these nifty shortcuts to undo some of those history-changing moves and get back to the proper timeline!&lt;/p&gt;

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

&lt;p&gt;If you only want to read the examples, you can skip to the next section. But if you want to follow along with the examples on your own terminal, run each line below as a command in your terminal to set up the demo repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;reflog-demo &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;cd &lt;/span&gt;reflog-demo &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; git init
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"file 1 content"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; file1.txt &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; git add &lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"add file1"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"file 2 content"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; file2.txt &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; git add &lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"add file2"&lt;/span&gt;
git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; my-new-branch
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"new branch file content"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; newBranchFile.txt &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; git add &lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"add newBranchFile"&lt;/span&gt;
git checkout master
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"file 3 content"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; file3.txt &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; git add &lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"add file3"&lt;/span&gt;
git checkout my-new-branch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Examples
&lt;/h2&gt;

&lt;p&gt;Here's an overview of the starting git history (using the command &lt;code&gt;git log --oneline --graph --all&lt;/code&gt;):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbv27lqw3xzwj4zb57u9b.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%2Fbv27lqw3xzwj4zb57u9b.png" alt="git log screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is a &lt;code&gt;master&lt;/code&gt; branch with 3 files, each added in a separate commit. There is also a separate &lt;code&gt;my-new-branch&lt;/code&gt; branch. This branch also has the first two files, but then splits off from master and has its own third file.&lt;/p&gt;

&lt;p&gt;And here are all the files in &lt;code&gt;my-new-branch&lt;/code&gt;:&lt;br&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%2Fp5tgkqwa1r7djie8t9o0.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%2Fp5tgkqwa1r7djie8t9o0.png" alt="screenshot of ls -1 command"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the desired state. When we mess it up in the examples below, our goal is to bring the repository back to this state.&lt;/p&gt;
&lt;h3&gt;
  
  
  1. Reset using a &lt;code&gt;reflog&lt;/code&gt; reference
&lt;/h3&gt;

&lt;p&gt;Let's say we're on &lt;code&gt;my-new-branch&lt;/code&gt; and we &lt;a href="https://www.atlassian.com/git/tutorials/rewriting-history/git-rebase" rel="noopener noreferrer"&gt;rebase&lt;/a&gt; onto master:&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%2Fyn4ifkyt7o178o2x15gu.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%2Fyn4ifkyt7o178o2x15gu.png" alt="Terminal screenshot running git rebase"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But Agh! We realize this was a mistake! Maybe the code stopped working after the rebase. Maybe there were some weird merge conflicts during the rebase and everything got messy. Either way, we want things to be the way they were before, but here is what our new git log shows:&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%2Fz75jgauge3csh8cxzfdj.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%2Fz75jgauge3csh8cxzfdj.png" alt="screenshot of rebased git log"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;...and all our &lt;code&gt;my-new-branch&lt;/code&gt; files are combined with the &lt;code&gt;master&lt;/code&gt; files:&lt;br&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%2Flvztassizg0xzwf9foiw.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%2Flvztassizg0xzwf9foiw.png" alt="screenshot of "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Apparently, our original commit (&lt;code&gt;6cde040&lt;/code&gt;) is &lt;em&gt;gone&lt;/em&gt;. How do we go back? We &lt;em&gt;could&lt;/em&gt; delete everything and re-clone, but we probably don't have a remote copy of our most recent changes to clone. We &lt;em&gt;could&lt;/em&gt; manually create a new branch off the old commit and re-add/delete the files that were there, but what a hassle!&lt;/p&gt;

&lt;p&gt;Instead, try running &lt;code&gt;git reflog&lt;/code&gt; to see some helpful points in history:&lt;br&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%2Fa68bghpazwvr45bw6lmj.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%2Fa68bghpazwvr45bw6lmj.png" alt="screenshot of git reflog output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="[https://git-scm.com/docs/git-reflog](https://git-scm.com/docs/git-reflog)"&gt;Git reflog&lt;/a&gt; shows everywhere our current working &lt;code&gt;HEAD&lt;/code&gt; was at, &lt;em&gt;including&lt;/em&gt; commits that were removed with destructive commands such as &lt;code&gt;git reset&lt;/code&gt; and &lt;code&gt;git rebase&lt;/code&gt;. Simply pick the commit before our destructive changes, do a hard reset to the &lt;a href="https://git-scm.com/docs/gitrevisions" rel="noopener noreferrer"&gt;gitrevision&lt;/a&gt; number (the one with the curly braces), and everything is reset to the way it was before the rebase!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; HEAD@&lt;span class="o"&gt;{&lt;/span&gt;3&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After running this command, our &lt;code&gt;git log&lt;/code&gt; shows us we're back to our original state with the original commits and the original files:&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%2Fugqktdxw8te53jfdgjwi.png" class="article-body-image-wrapper"&gt;&lt;img alt="Original tree" 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%2Fugqktdxw8te53jfdgjwi.png"&gt;&lt;/a&gt;Ahhhh, good ol' un-touched branches!&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Reset to &lt;code&gt;ORIG_HEAD&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;"&lt;em&gt;But Zak,&lt;/em&gt;" you might say, "&lt;em&gt;that reflog output is kind of confusing, and it's hard to tell exactly which reflog line to go back to.&lt;/em&gt;"&lt;/p&gt;

&lt;p&gt;Agreed! Luckily, there's an EVEN EASIER way!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; ORIG_HEAD
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;ORIG_HEAD&lt;/code&gt; automatically points to the state before the most recent destructive change, so we can easily undo our most recent &lt;code&gt;rebase&lt;/code&gt; or &lt;code&gt;reset&lt;/code&gt; with a single command! Running &lt;code&gt;git reset --hard ORIG_HEAD&lt;/code&gt; here does the exact same thing as running &lt;code&gt;git reset --hard HEAD@{3}&lt;/code&gt; in the example above without needing to hunt down a specific revision!&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Reset to a relative time
&lt;/h3&gt;

&lt;p&gt;🌟🌟🌟&lt;strong&gt;&lt;em&gt;WARNING: THIS IS REALLY COOL&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Resetting to &lt;code&gt;ORIG_HEAD&lt;/code&gt; is great, but what if we've &lt;em&gt;really&lt;/em&gt; gone down a rabbit hole of destructive changes. Let's take the rebase from the last example, and add a few more steps to it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git rebase master
git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; HEAD~2
git commit &lt;span class="nt"&gt;--amend&lt;/span&gt; &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s1"&gt;'shablagoo!'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why did we do this? I don't know ¯\_(ツ)_/¯. Someone on Stack Overflow probably said it was a good idea, so we tried it on a whim and, well, things got weird:&lt;br&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%2Fc6sq1smls5ebkohax2ed.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%2Fc6sq1smls5ebkohax2ed.png" alt="Screenshot of log after changes"&gt;&lt;/a&gt;&lt;br&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%2Fxe3m1krntlf9u3snr33f.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%2Fxe3m1krntlf9u3snr33f.png" alt="Screenshot of files after changes"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The commits are all out of order, and we are &lt;em&gt;missing files&lt;/em&gt;. How can we undo this??? We made several destructive changes, so &lt;code&gt;ORIG_HEAD&lt;/code&gt; isn't going to work. We can check &lt;code&gt;git reflog&lt;/code&gt;, but there's so many changes that happened that it might be hard to find the right one. &lt;strong&gt;All we want is for our branch to look like it did 5 minutes ago before the changes.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Try this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; HEAD@&lt;span class="o"&gt;{&lt;/span&gt;5.minutes.ago&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;...and afterwards, you'll see the branch in the exact state it was 5 minutes ago:&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%2Fugqktdxw8te53jfdgjwi.png" class="article-body-image-wrapper"&gt;&lt;img alt="Original tree" 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%2Fugqktdxw8te53jfdgjwi.png"&gt;&lt;/a&gt;Ahhhh, good ol' un-touched branches!&lt;/p&gt;

&lt;p&gt;Yes, you read that right: &lt;strong&gt;This command literally tells Git in plain English to return to some time in the past, and Git does it!&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;This is using a powerful concept in git called &lt;a href="[https://git-scm.com/docs/gitrevisions](https://git-scm.com/docs/gitrevisions)"&gt;gitrevisions&lt;/a&gt;. Some other examples include: &lt;code&gt;HEAD@{1.day.2.hours.ago}&lt;/code&gt;, &lt;code&gt;HEAD@{yesterday}&lt;/code&gt;, &lt;code&gt;HEAD@{2020-01-01 18:30:00}&lt;/code&gt;, &lt;code&gt;HEAD@{12:43}&lt;/code&gt;. In other words: TIME TRAVEL IS POSSIBLE IN GIT!!!&lt;/p&gt;

&lt;h2&gt;
  
  
  Caveats
&lt;/h2&gt;

&lt;p&gt;The techniques above are powerful, but there are a few limitations to keep in mind:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Only works for your local terminal&lt;/strong&gt; – your &lt;code&gt;reflog&lt;/code&gt; and gitrevisions are stored locally, but aren't shared when you push to a remote repository&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Only works for committed files&lt;/strong&gt; – if you've deleted uncommitted files, these aren't stored in Git anywhere. Good reason to &lt;a href="[https://sethrobertson.github.io/GitBestPractices/#commit](https://sethrobertson.github.io/GitBestPractices/#commit)"&gt;commit early and often&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Recap
&lt;/h2&gt;

&lt;p&gt;So, to summarize, here are some ways to fix your repo after you &lt;code&gt;reset&lt;/code&gt; or &lt;code&gt;rebase&lt;/code&gt; your code into an unusable state:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;git reflog&lt;/code&gt; to pick a point in history, then undo your recent changes &lt;code&gt;git reset --hard HEAD@{&amp;lt;number&amp;gt;}&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;As a shortcut, use &lt;code&gt;git reset --hard ORIG_HEAD&lt;/code&gt; to undo the most recent destructive operation&lt;/li&gt;
&lt;li&gt;Reset to &lt;code&gt;&amp;lt;refname&amp;gt;@&amp;lt;relative time&amp;gt;&lt;/code&gt; to time travel back to a happier state (e.g. &lt;code&gt;git reset --hard HEAD@{10.minutes.ago}&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope this helps someone out there! Let me know in the comments if you have any questions or any other go-to methods for undoing git mistakes!&lt;/p&gt;




&lt;center&gt;_Did you find this this article useful? Feel free to follow my profile below or [follow me on Twitter](https://twitter.com/ZakLaughton) for more developer tips and article announcements!_&lt;/center&gt;






</description>
      <category>git</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>productivity</category>
    </item>
    <item>
      <title>The only 4 Regex Notations You Need To Know (to start) ❤️</title>
      <dc:creator>Zak Laughton</dc:creator>
      <pubDate>Wed, 19 Feb 2020 03:56:28 +0000</pubDate>
      <link>https://dev.to/zaklaughton/boost-your-editor-skills-and-fall-in-love-with-regex-all-over-again-or-for-the-first-time-1l70</link>
      <guid>https://dev.to/zaklaughton/boost-your-editor-skills-and-fall-in-love-with-regex-all-over-again-or-for-the-first-time-1l70</guid>
      <description>&lt;p&gt;You know what's awesome?! Regex is! I use it almost every day to search through my codebase, and occasionally to parse text input in my code. &lt;em&gt;(If you're unfamiliar: regex, short for &lt;a href="https://en.wikipedia.org/wiki/Regular_expression"&gt;&lt;strong&gt;reg&lt;/strong&gt;ular &lt;strong&gt;ex&lt;/strong&gt;pression&lt;/a&gt;, is a powerful technique for searching large amounts of text using a specialized string of characters.)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;But I've heard something surprising lately from many developers: &lt;strong&gt;"I hate regex"&lt;/strong&gt;. What?? Why would anyone say something so horrible about something that's so &lt;em&gt;fun&lt;/em&gt;? I have a theory...&lt;/p&gt;

&lt;p&gt;I'm going to go out on a limb here and make a bold claim: nobody hates regex, they just hate implementing it into whatever programming language they use (hear me out on this). Even with a perfect grasp of how regex works, it can be difficult to figure out what the regex is actually doing when sending it through a coding interface.&lt;/p&gt;

&lt;p&gt;As an example, here's a nice easy search for the word &lt;code&gt;episode&lt;/code&gt; using regex &lt;br&gt;
 in a text editor where we can easily see the results:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zbo8--UN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tmi955zd0grfc109ffoa.gif" class="article-body-image-wrapper"&gt;&lt;img alt="Searching regex in an editor" src="https://res.cloudinary.com/practicaldev/image/fetch/s--zbo8--UN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tmi955zd0grfc109ffoa.gif"&gt;&lt;/a&gt;"Ah, yes. This is everywhere my code has the word &lt;code&gt;episode&lt;/code&gt;. Lovely!"&lt;/p&gt;

&lt;p&gt;...but here's an example where we're searching for the same word in a &lt;code&gt;myText&lt;/code&gt; variable using JavaScript regex functions:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OTrJJexH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/x0001lkt3k920rfe88n7.gif" class="article-body-image-wrapper"&gt;&lt;img alt="Searching regex in an editor" src="https://res.cloudinary.com/practicaldev/image/fetch/s--OTrJJexH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/x0001lkt3k920rfe88n7.gif"&gt;&lt;/a&gt;"Did the query work? Why are there 3 different methods for searching regex? Am I using the right one? Why do they all return a different data type? Are they searching the right data?? Is this case sensitive??? WHY IS REGEX SO COMPLICATED?!!?!?!"&lt;/p&gt;

&lt;p&gt;Clearly, regex isn't the problem here! The problem is figuring out how to use regex in these dang functions! Hating regex because of confusing code implementation is like hating cake batter for burning your cake. And do you know who hates cake batter? &lt;em&gt;Nobody&lt;/em&gt;. &lt;em&gt;&lt;strong&gt;Cake batter is delicious.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So in this article, I'm going to focus on just eating the cake batter. I'm going to show you the powers of regex by using it to search code in a text editor, without the pesky implementation of a programming language. I'll show you how it's an essential tool to search your files, and hopefully teach you some new delicious tricks along the way to help when you do need to use it in your code.&lt;/p&gt;

&lt;h1&gt;
  
  
  Most useful regex notations
&lt;/h1&gt;

&lt;p&gt;There are &lt;a href="https://www.princeton.edu/~mlovett/reference/Regular-Expressions.pdf"&gt;entire textbooks&lt;/a&gt; written on how to write regex queries, but you only need a few basics to start seeing some big results. Below I've listed the 4 regex notations I use most often to quickly narrow down large sets of text to a single snippet.&lt;/p&gt;

&lt;p&gt;The examples below will be using &lt;a href="https://code.visualstudio.com/"&gt;Visual Studio Code&lt;/a&gt;, but most other code text editors such as &lt;a href="https://www.sublimetext.com/"&gt;Sublime&lt;/a&gt; and &lt;a href="https://atom.io/"&gt;Atom&lt;/a&gt; have similar regex search functionality.  If you're following along, you can open up a text search in your editor using &lt;code&gt;Ctrl&lt;/code&gt; + &lt;code&gt;F&lt;/code&gt; (on mac: &lt;code&gt;⌘&lt;/code&gt; + &lt;code&gt;F&lt;/code&gt;), or search all your files using &lt;code&gt;Ctrl&lt;/code&gt; + &lt;code&gt;Shift&lt;/code&gt; + &lt;code&gt;F&lt;/code&gt; (on mac: &lt;code&gt;⌘&lt;/code&gt; + &lt;code&gt;Shift&lt;/code&gt; + &lt;code&gt;F&lt;/code&gt;). Be sure the regex option (the one that looks like &lt;code&gt;.*&lt;/code&gt;) is enabled, and the rest are disabled:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OXliVox_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1eaf5q84nrzxudavxpvj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OXliVox_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1eaf5q84nrzxudavxpvj.png" alt="Search bar settings screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Simple text search
&lt;/h3&gt;

&lt;p&gt;At its base functionality, it's important to remember that regex will just search  regular ol' text. If you're searching for text that just has letters, numbers and spaces, just type the text as your query.&lt;/p&gt;

&lt;p&gt;If there are any special characters or punctuation, add a backslash &lt;code&gt;\&lt;/code&gt; before the character. This is because many special characters have meaning in regex queries that changes the search behavior. Adding a backslash "escapes" the character and tells regex to just search for the character itself. Example: to search for a period, type &lt;code&gt;\.&lt;/code&gt;, to search for an opening parenthesis, type &lt;code&gt;\(&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Y7lDGe5w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tcp87x8l2q78bfs4oh92.gif" class="article-body-image-wrapper"&gt;&lt;img alt="Searching demo gif" src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y7lDGe5w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tcp87x8l2q78bfs4oh92.gif"&gt;&lt;/a&gt;Searching for &lt;code&gt;atLatestEpisode\(&lt;/code&gt; matches all occurrences of &lt;code&gt;atLatestEpisode(&lt;/code&gt; in the code.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Wildcard &lt;code&gt;.*&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;.*&lt;/code&gt; is a wildcard that matches any number of characters. Use it to match strings where you're not certain of some of characters in the middle.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--v5cYT8d0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ftm8mjweq29nmxrv9rfb.gif" class="article-body-image-wrapper"&gt;&lt;img alt="Wildcard demo gif" src="https://res.cloudinary.com/practicaldev/image/fetch/s--v5cYT8d0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ftm8mjweq29nmxrv9rfb.gif"&gt;&lt;/a&gt;Searching &lt;code&gt;at.*Episode\(&lt;/code&gt; matches both &lt;code&gt;atEarliestEpisode(&lt;/code&gt; and &lt;code&gt;atLatestEpisode(&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Capturing groups and backreferences &lt;code&gt;()&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.regular-expressions.info/brackets.html"&gt;Capturing groups&lt;/a&gt; are a way to "capture" parts of your query with parenthesis to use for special functionality. On their own, these parenthesis won't impact the search results. For example, in the query &lt;code&gt;(shab)la(go)o&lt;/code&gt;, both &lt;code&gt;shab&lt;/code&gt; and &lt;code&gt;go&lt;/code&gt; are captured groups, but the query will still match all instances of &lt;code&gt;shablagoo&lt;/code&gt; in the text.&lt;/p&gt;

&lt;p&gt;So why would you want to do this? A few reasons, but one of the most useful reasons in a text editor is to reference the text as a variable. Each capturing group is numbered by the order it appears and is assigned a numbered variable you can use to insert the captured text somewhere else (this is also known as a &lt;a href="https://www.regular-expressions.info/backref.html"&gt;backreference&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Where this gets &lt;em&gt;really&lt;/em&gt; powerful in an editor is using these backreferences as search replacement variables. For example, if I search for &lt;code&gt;(always)(blue)&lt;/code&gt;, then  set the replacement string to &lt;code&gt;$2$1&lt;/code&gt;, then every occurrence of &lt;code&gt;alwaysblue&lt;/code&gt; will be replaced with &lt;code&gt;bluealways&lt;/code&gt;. This is because the first capturing group, &lt;code&gt;always&lt;/code&gt;, is assigned to &lt;code&gt;$1&lt;/code&gt;, and the second capturing group, &lt;code&gt;blue&lt;/code&gt;, is assigned to &lt;code&gt;$2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This type of find and replace rearrangement is especially useful if you want to change the format of several records in a large dataset. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ONfDX3zn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1dgaseefc08v5674as91.gif" class="article-body-image-wrapper"&gt;&lt;img alt="Backreference demo gif" src="https://res.cloudinary.com/practicaldev/image/fetch/s--ONfDX3zn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1dgaseefc08v5674as91.gif"&gt;&lt;/a&gt;This gif shows a great way to capture and rearrange data. First, we select all names by changing the first and last name to wildcards. Next, we place the wildcards in capturing groups to be referenced in the replace field. Finally, we use the number of each capturing group to re-insert the first and last names into whatever new format we want!&lt;/p&gt;

&lt;h2&gt;
  
  
  Word boundary &lt;code&gt;\b&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;The last one I'm going to cover here is the &lt;a href="https://www.regular-expressions.info/wordboundaries.html"&gt;word boundary&lt;/a&gt;, which I use all the time when searching short words in code. Let's say you want to find any time the word &lt;code&gt;user&lt;/code&gt; shows up in your files. You can do a regex search of all files for &lt;code&gt;user&lt;/code&gt;, but this will also include partial matches such as &lt;code&gt;username&lt;/code&gt;, &lt;code&gt;enduser&lt;/code&gt;, and &lt;code&gt;obtuseRicearoni&lt;/code&gt;. That's where the word boundary comes in.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;\b&lt;/code&gt; represents a boundary between a word and a non-word character. Or more simply – the edge of a word. (Note: a "word" character here means a letter, a number, or an underscore. A "non-word" character is everything else). This means you can search for &lt;code&gt;\buser\b&lt;/code&gt; and it will only return instances of &lt;code&gt;user&lt;/code&gt; that are not a part of a longer word or variable name. Pretty cool!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XOMqJbB---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/oaqnsal5m91mif5bhct8.gif" class="article-body-image-wrapper"&gt;&lt;img alt="Backreference demo gif" src="https://res.cloudinary.com/practicaldev/image/fetch/s--XOMqJbB---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/oaqnsal5m91mif5bhct8.gif"&gt;&lt;/a&gt;Searching &lt;code&gt;episode&lt;/code&gt; in this file returns waaaay too many results with longer names that &lt;em&gt;include&lt;/em&gt; episode. You can narrow it down to search just for the word by searching for &lt;code&gt;\bepisode\b&lt;/code&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Wrap-up
&lt;/h1&gt;

&lt;p&gt;That's it! These tips above can help optimize your processes, make it easier to search through large files, and hopefully help boost confidence when implementing regex in your own code.&lt;/p&gt;

&lt;p&gt;When you do implement regex in your programming language of choice, I strongly recommend trying it out in a text editor first to ensure you've got the proper regex before adding the programming complications. There are also super helpful sites such as &lt;a href="https://regexr.com/"&gt;https://regexr.com/&lt;/a&gt; and &lt;a href="https://regexr.com/"&gt;https://regexr.com/&lt;/a&gt; that provide great cheatsheets and playgrounds for testing your regex.&lt;/p&gt;

&lt;p&gt;What did I miss? Any other regex notations you love that I left out? Or any questions about using regex? Feel free to let me know in the comments!&lt;/p&gt;





&lt;center&gt;&lt;em&gt;Did you find this this article useful? Feel free to subscribe to my articles below or &lt;a href="https://twitter.com/ZakLaughton"&gt;follow me on Twitter&lt;/a&gt; for more developer tips and article announcements!&lt;/em&gt;&lt;/center&gt;





</description>
      <category>regex</category>
      <category>productivity</category>
      <category>vscode</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Every VS Code extension a JavaScript web developer should have in 2021 (with gifs!)</title>
      <dc:creator>Zak Laughton</dc:creator>
      <pubDate>Sun, 09 Feb 2020 23:09:05 +0000</pubDate>
      <link>https://dev.to/zaklaughton/every-vs-code-extension-a-javascript-web-developer-should-have-in-2020-with-gifs-2b6n</link>
      <guid>https://dev.to/zaklaughton/every-vs-code-extension-a-javascript-web-developer-should-have-in-2020-with-gifs-2b6n</guid>
      <description>&lt;p&gt;Visual Studio Code is a powerful editor out of the box, but there are &lt;a href="https://code.visualstudio.com/docs/editor/extension-gallery"&gt;many many VS Code extensions&lt;/a&gt; to make it even more powerful!&lt;/p&gt;

&lt;p&gt;If you're new to VS Code or coding in general, I recommend reading through everything here to see if there are new ways you can optimize your workflow. If you're a VS Code veteran, see if there's anything here you don't have, and let me know in the comments if I missed anything!&lt;/p&gt;




&lt;p&gt;&lt;em&gt;VS Code is constantly updating, and I regularly review my extensions to figure out which ones are and are not adding value. I'll be keeping this list updated as I add and remove extensions.&lt;/em&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Must-have extensions (alphabetical)
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  Better Comments
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--G0InyBBR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/md8xqxb73889sp8cvcry.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G0InyBBR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/md8xqxb73889sp8cvcry.gif" alt="Better Comments demo gif"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=aaron-bond.better-comments"&gt;Better Comments&lt;/a&gt; shows your comments as different colors depending on how they're prefixed. Great to quickly visually scan and identify important pieces of your code. Keep in mind these colors only show if you have the extension, so this is best for personal use cases.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  Bookmarks
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dDw-OGJK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/12ofd3pcsnr57bgm2vax.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dDw-OGJK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/12ofd3pcsnr57bgm2vax.gif" alt="Bookmarks"&gt;&lt;/a&gt;&lt;br&gt;
Have you ever been working on a feature that involves 10 functions across several files, forcing you to hop around and re-find each function? &lt;a href="https://marketplace.visualstudio.com/items?itemName=alefragnani.Bookmarks"&gt;Bookmarks&lt;/a&gt; helps you keep track of all the code that's important to you. Just add a bookmark to easily find your spot later!&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  Bracket Pair Colorizer
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZmnL4fIa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ujl784wj8c0i9i6f0byb.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZmnL4fIa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ujl784wj8c0i9i6f0byb.gif" alt="Bracket Pair Colorizer demo gif"&gt;&lt;/a&gt;&lt;br&gt;
Trying to find missing parenthesis is my least favorite programming activity. Luckily, &lt;a href="https://marketplace.visualstudio.com/items?itemName=CoenraadS.bracket-pair-colorizer"&gt;Bracket Pair Colorizer&lt;/a&gt; makes this a lot easier by color-coding all corresponding parenthesis and brackets. &lt;em&gt;(NOTE: This one has some known performance issues, and theres a beta version of &lt;a href="https://marketplace.visualstudio.com/items?itemName=CoenraadS.bracket-pair-colorizer"&gt;Bracket Pair Colorizer 2&lt;/a&gt; out to fix this. Thanks for the tip, &lt;a href="https://twitter.com/gerrit_alex/status/1226772068806594560"&gt;@garret_alex&lt;/a&gt;)&lt;/em&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  change-case
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--brwRcx_w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/jqauylv6n1xtyyfuo799.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--brwRcx_w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/jqauylv6n1xtyyfuo799.gif" alt="change-case demo gif"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=wmaurer.change-case"&gt;change-case&lt;/a&gt; gives an easy way to change a word or variable name to all sorts of cases including &lt;code&gt;camelCase&lt;/code&gt;, &lt;code&gt;snake_case&lt;/code&gt;, &lt;code&gt;TitleCase&lt;/code&gt;, and more!&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  Code Spell Checker
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--afxeqtsd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1zcibof0dh3o9acoqd49.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--afxeqtsd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1zcibof0dh3o9acoqd49.gif" alt="Code Spell Checker demo gif"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker"&gt;Code Spell Checker&lt;/a&gt; finds typos and misspelled words, even if they're in the middle of a variable name. This is one I didn't truly realize the value of until I had it installed and started finding all my little typos. Turns out, having a spell checker in a code editor is just as useful as having one in a word processor!&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  ES7 React/Redux/GraphQL/React-Native snippets
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nEjIqiI---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ozqafpz73zrsz1ege5bs.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nEjIqiI---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ozqafpz73zrsz1ege5bs.gif" alt="Snippets demo gif"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=dsznajder.es7-react-js-snippets"&gt;ES7 Snippets&lt;/a&gt; has so many useful tools for autofilling in boilerplate text. Saves a ton of time whenever I'm writing imports or React components.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  ESLint
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FnGqSJlm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/udrjqbrukiup53kgwklc.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FnGqSJlm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/udrjqbrukiup53kgwklc.gif" alt="ESLint demo gif"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint"&gt;ESLint&lt;/a&gt; is a great linter that will pick out syntax errors for you in your code to catch issues before you even run your code. Requires &lt;a href="https://eslint.org/docs/user-guide/configuring"&gt;configuration of ESLint&lt;/a&gt; in your project.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  GitLens
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--36j0IfCj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.imgur.com/3siDOZD.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--36j0IfCj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.imgur.com/3siDOZD.gif" alt="GitLens demo gif"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens"&gt;GitLens&lt;/a&gt; is a feature-packed extension that gives you all sorts of insight into your repository's commit history. Personally, I use it most often to see who wrote code inline, see previous versions of files, and compare HEAD to other commits/branches.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  glean
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FjKmeYhv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tdwhqt39j2ted8vpriyt.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FjKmeYhv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tdwhqt39j2ted8vpriyt.gif" alt="glean demo gif"&gt;&lt;/a&gt;&lt;br&gt;
If you're a React developer, you probably often find yourself breaking out large components into smaller ones in separate files as well as switching between class and functional components. &lt;a href="https://marketplace.visualstudio.com/items?itemName=wix.glean"&gt;glean&lt;/a&gt; automates all this for you and automatically inserts all the needed boilerplate.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  Import Cost
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kaRcqzMi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/oukn7v142pueo1whagr8.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kaRcqzMi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/oukn7v142pueo1whagr8.gif" alt="Import Cost demo gif"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=wix.vscode-import-cost"&gt;Import Cost&lt;/a&gt; helps you to be cognizant of the size of your imports. It shows the size of each import inline, and shows in red and yellow warning colors if the import is larger than normal.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  indent-rainbow
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QiiOFuBR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pffij9jtrpzkkkhdghiq.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QiiOFuBR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pffij9jtrpzkkkhdghiq.gif" alt="indent-rainbow demo gif"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=oderwat.indent-rainbow"&gt;indent-rainbow&lt;/a&gt; makes it effortless to see indents at a glance. Plus, it's super pretty, right?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  javascript console utils
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--a9EcMHFu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/jgooe2ome7e7tfoxzew0.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--a9EcMHFu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/jgooe2ome7e7tfoxzew0.gif" alt="javascript console utils demo gif"&gt;&lt;/a&gt;&lt;br&gt;
Find yourself &lt;code&gt;console.log()&lt;/code&gt;-ing a lot? &lt;a href="https://marketplace.visualstudio.com/items?itemName=whtouche.vscode-js-console-utils"&gt;javascript console utils&lt;/a&gt; automates this for you by inserting &lt;code&gt;console.log()&lt;/code&gt; statements into your code, complete with the plaintext variable name and variable value. There's even a hotkey to remove all &lt;code&gt;console.log()&lt;/code&gt; statements when you're done with them!&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  Prettier
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lffDYu1o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tjzvre4nuubw4wz85u1n.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lffDYu1o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tjzvre4nuubw4wz85u1n.gif" alt="Prettier demo gif"&gt;&lt;/a&gt;&lt;br&gt;
This one's important. I'd even go as far as to say that nobody should code without &lt;a href="https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode"&gt;Prettier&lt;/a&gt;. Prettier auto-formats your code with &lt;code&gt;alt&lt;/code&gt; + &lt;code&gt;shift&lt;/code&gt; + &lt;code&gt;F&lt;/code&gt;, or you can have it auto-format on every save. This saves a TON of time over remembering every semicolon and indent.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  Relative Path
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_sD919N4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wqt6a34240y50065rkxy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_sD919N4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wqt6a34240y50065rkxy.gif" alt="Relative Path demo gif"&gt;&lt;/a&gt;&lt;br&gt;
Ever work in a large codebase trying to figure out how to reference another file? Exactly how many &lt;code&gt;../&lt;/code&gt;'s do you need to get back to the proper directory, then what's the path back down? &lt;a href="https://marketplace.visualstudio.com/items?itemName=jakob101.RelativePath"&gt;Relative Path&lt;/a&gt; lets you search all files and auto-inserts the path relative to the file you're in. No tree counting needed!&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  Settings Sync
&lt;/h3&gt;


&lt;center&gt;&lt;em&gt;There's not a great way to demo this one, so here's my favorite gif of all time instead:&lt;/em&gt;&lt;/center&gt;

&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7YWeBme_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/b3lsyiwleuwfvwafx5qc.gif" alt="Cat and Shaq wiggling"&gt;
So, about the extension: When you've got a sweet setup in your editor, &lt;a href="https://marketplace.visualstudio.com/items?itemName=Shan.code-settings-sync"&gt;Settings Sync&lt;/a&gt; gives a painless way to sync all your VS Code settings and extensions across your workstations by saving your configuration to a GitHub gist. They've even made several improvements over the past year to make syncing/authentication &lt;em&gt;much&lt;/em&gt; easier.&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  Toggle Quotes
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ONSt89ZW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/kmkuny531n8jh1ve0oyj.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ONSt89ZW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/kmkuny531n8jh1ve0oyj.gif" alt="Toggle Quotes demo gif"&gt;&lt;/a&gt;&lt;br&gt;
With &lt;a href="https://marketplace.visualstudio.com/items?itemName=BriteSnow.vscode-toggle-quotes"&gt;Toggle Quotes&lt;/a&gt;, just use &lt;code&gt;⌘&lt;/code&gt; + &lt;code&gt;'&lt;/code&gt; (or &lt;code&gt;ctrl&lt;/code&gt; + &lt;code&gt;'&lt;/code&gt;) to cycle your strings between using &lt;code&gt;`&lt;/code&gt;, &lt;code&gt;'&lt;/code&gt;, and &lt;code&gt;"&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  Version Lens
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3MxPYRXl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lklf2900oy6m3nosykka.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3MxPYRXl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lklf2900oy6m3nosykka.gif" alt="Version Lens demo gif"&gt;&lt;/a&gt;&lt;br&gt;
It can be a hassle to keep track of all the latest versions of your npm packages. &lt;a href="https://marketplace.visualstudio.com/items?itemName=pflannery.vscode-versionlens"&gt;Version Lens&lt;/a&gt; shows you inline how your installed versions in &lt;code&gt;package.json&lt;/code&gt; compare to the current versions.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Bonus
&lt;/h1&gt;

&lt;p&gt;These items don't dramatically improve my day-to-day productivity, but golly, I sure do like them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=dracula-theme.theme-dracula"&gt;Dracula Offical&lt;/a&gt;&lt;/strong&gt; – my preferred color theme&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=file-icons.file-icons"&gt;file-icons&lt;/a&gt;&lt;/strong&gt; – gives unique file icons to quickly identify types in the file browser. I find it most useful for quickly distinguishing between &lt;code&gt;.ts&lt;/code&gt;, &lt;code&gt;.js&lt;/code&gt;, &lt;code&gt;.test.ts&lt;/code&gt;, &amp;amp; &lt;code&gt;.test.js&lt;/code&gt;.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--15SEeR5k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zd29hvp461jlsv7jcbvk.png" alt="Screenshot of file browser with icons"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://github.com/tonsky/FiraCode"&gt;Fira Code&lt;/a&gt;&lt;/strong&gt; – a spiffy-looking font that includes some sweet ligatures! This means that inequality symbols such as &lt;code&gt;&amp;lt;=&lt;/code&gt; and &lt;code&gt;!==&lt;/code&gt; show up as a single character. It hasn't &lt;em&gt;improved&lt;/em&gt; my coding, per se, but it has made me feel cooler.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CR9Gi9OS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/a1fvx517t47ukjk7cjfg.png" alt="Screenshot of ligatures"&gt;
ℹ️ &lt;em&gt;Other ligatured fonts recommended by readers: &lt;a href="https://www.jetbrains.com/lp/mono/"&gt;JetBrains Mono&lt;/a&gt;, &lt;a href="https://github.com/microsoft/cascadia-code/"&gt;Cascadia Code&lt;/a&gt;, &lt;a href="https://www.recursive.design/"&gt;Recursive Sans &amp;amp; Mono&lt;/a&gt;&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;NOTE: Ligatures can be &lt;a href="https://practicaltypography.com/ligatures-in-programming-fonts-hell-no.html"&gt;a controversial topic among coders&lt;/a&gt;. My argument for using them is that I think they're sexy. I rest my case.&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=vscodevim.vim"&gt;Vim&lt;/a&gt;&lt;/strong&gt; – When I first started coding, I got really into becoming a &lt;a href="https://www.vim.org/"&gt;Vim editor&lt;/a&gt; power user. The functionality of VS Code goes far beyond the utility I get from Vim, but sometimes I miss those old "Change 100 lines with  5 cryptic keystrokes" features. I mostly leave this disabled, but I fire it up every once in a while when I'm feeling spunky.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Extensions I no longer use
&lt;/h1&gt;

&lt;p&gt;Sometimes I stop using an extension because the functionality is added to base VS Code, or maybe the extension isn't as useful as I once thought it was. Here are some extensions I used heavily once, but eventually uninstalled:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=SirTori.indenticator"&gt;Indenticator&lt;/a&gt;&lt;/strong&gt; – provided a great way to visually see your indents using highlighted vertical lines. This now comes standard in VS Code, though &lt;a href="https://marketplace.visualstudio.com/items?itemName=SirTori.indenticator#remarks"&gt;there are some differences&lt;/a&gt;. VS Code Native settings: &lt;a href="https://code.visualstudio.com/docs/getstarted/userinterface#_indent-guides"&gt;&lt;code&gt;editor.renderIndentGuides&lt;/code&gt;&lt;/a&gt;, &lt;a href="https://code.visualstudio.com/docs/getstarted/settings"&gt;&lt;code&gt;editor.highlightActiveIndentGuide&lt;/code&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-close-tag"&gt;Auto-close tag&lt;/a&gt;&lt;/strong&gt; &amp;amp; &lt;strong&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-rename-tag"&gt;Auto Rename Tag&lt;/a&gt;&lt;/strong&gt; – automatically provided closing HTML tags whenever you typed an opening tag, and kept them updated to match each other. Most of this functionality is now included in VS Code, and these plugins were known to cause big performance issues (&lt;a href="https://dev.to/mattwaler/comment/lb40"&gt;thanks for the tip, Matt Waler&lt;/a&gt;). Native VS Code settings: &lt;a href="https://code.visualstudio.com/docs/languages/html#_close-tags"&gt;&lt;code&gt;html.autoClosingTags&lt;/code&gt;&lt;/a&gt;, &lt;a href="https://code.visualstudio.com/docs/languages/html#_mirror-cursor"&gt;&lt;code&gt;html.mirrorCursorOnMatchingTag&lt;/code&gt;&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=naumovs.color-highlight"&gt;Color Highlight&lt;/a&gt;&lt;/strong&gt; – Highlights any CSS color values with the color they represent. VS Code now natively shows a colored box next to the value, which is good enough for me: &lt;a href="https://code.visualstudio.com/docs/languages/css#_syntax-coloring-color-preview"&gt;&lt;code&gt;editor.colorDecorators&lt;/code&gt;&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Anything else?
&lt;/h1&gt;

&lt;p&gt;What did I miss? Is there any other extension that helps you be a productive coder? Please let me know in the comments!&lt;/p&gt;





&lt;center&gt;&lt;em&gt;Did you find this this article useful? Feel free to subscribe to my articles below or &lt;a href="https://twitter.com/ZakLaughton"&gt;follow me on Twitter&lt;/a&gt; for more developer tips and article announcements!&lt;/em&gt;&lt;/center&gt;





</description>
      <category>vscode</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>productivity</category>
    </item>
    <item>
      <title>The only 3 steps you need to mock an API call in Jest</title>
      <dc:creator>Zak Laughton</dc:creator>
      <pubDate>Sun, 02 Feb 2020 05:51:51 +0000</pubDate>
      <link>https://dev.to/zaklaughton/the-only-3-steps-you-need-to-mock-an-api-call-in-jest-39mb</link>
      <guid>https://dev.to/zaklaughton/the-only-3-steps-you-need-to-mock-an-api-call-in-jest-39mb</guid>
      <description>&lt;p&gt;I recently found myself working in a Javascript codebase where I needed to implement new Jest tests. I knew very little at the time about writing tests, so I looked to Jest docs and existing patterns in the codebase to figure out best practices and how to do it. It was fairly straightforward, and I even found myself enjoying testing. But I could not for the life of me reliably mock an API call.&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%2Fks0sfsk19qw32d6wiy8j.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fks0sfsk19qw32d6wiy8j.jpg" alt="Dog with caption " width="512" height="288"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The docs seemed clear, and the existing code appeared to have good patterns, but there were just so many ways to mock things. The existing tests used all sorts of mocking methods such as &lt;code&gt;jest.genMockFromModule()&lt;/code&gt;, &lt;code&gt;jest.spyOn()&lt;/code&gt;, and &lt;code&gt;jest.mock()&lt;/code&gt;. Sometimes the mocks were inline, sometimes they were in variables, and sometimes they were imported and exported in magical ways from mysterious &lt;code&gt;__mocks__&lt;/code&gt; folders. I used these techniques interchangeably every time I got a burst of confidence in understanding, only to find myself stumbling over the different methods and their effects. I had no idea what I was doing.&lt;/p&gt;

&lt;h2&gt;
  
  
  The issue
&lt;/h2&gt;

&lt;p&gt;The issue was that I was trying to learn how to run before I even knew how to walk. Jest has many powerful ways to mock functions and optimize those mocks, but they're all useless if you don't know how to make a simple mock in the first place. And while the Jest documentation provides a lot of great insight and techniques, &lt;strong&gt;I couldn't figure out where to start&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In this article, I hope to give you absolute basics to mock an API call so you can benefit from my 2020 hindsight (heh). If you're going crazy like I was because you can't figure out how to &lt;em&gt;just make a simple damn mock&lt;/em&gt;, Start here…&lt;/p&gt;

&lt;p&gt;&lt;em&gt;(NOTE: The code below was written in Node.js, but the mocking concepts also apply to frontend Javascript and ES6 modules)&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The unmocked code
&lt;/h2&gt;

&lt;p&gt;We're going to be testing this &lt;code&gt;getFirstAlbumTitle()&lt;/code&gt; function, which fetches an array of albums from an API and returns the title of the first album:&lt;/p&gt;

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

&lt;span class="c1"&gt;// index.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;axios&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;axios&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getFirstAlbumTitle&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.typicode.com/albums&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;getFirstAlbumTitle&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;



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

&lt;/div&gt;
&lt;p&gt;...and here's our initial mock-less test for this function, which verifies the function actually returns the title of the first album in the list:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="c1"&gt;// index.test.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getFirstAlbumTitle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./index&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;returns the title of the first album&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getFirstAlbumTitle&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;  &lt;span class="c1"&gt;// Run the function&lt;/span&gt;
  &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toEqual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;quidem molestiae enim&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// Make an assertion on the result&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;


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

&lt;/div&gt;
&lt;p&gt;The test above does its job, but the test actually makes a network request to an API when it runs. This opens the test up to all sorts of false negatives if the API isn't working exactly as expected (e.g. the list order changes, API is down, dev machine loses network connection, etc.). Not to mention, making these requests in a large number of tests can bring your test runs to a slow crawl.&lt;/p&gt;

&lt;p&gt;But how can we change this? The API request is being made with axios as a part of &lt;code&gt;getFirstAlbumTitle()&lt;/code&gt;. How in the world are we supposed to reach &lt;em&gt;inside&lt;/em&gt; the function and change the behavior?&lt;/p&gt;
&lt;h2&gt;
  
  
  Mock it in 3 steps
&lt;/h2&gt;

&lt;p&gt;Alright, here it is. This is the big secret that would have saved me mountains of time as I was wrestling with learning mocks. To mock an API call in a function, you just need to do these 3 steps:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Import the module you want to mock &lt;em&gt;into your test file.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;2. &lt;code&gt;jest.mock()&lt;/code&gt; the module.&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;3. Use &lt;code&gt;.mockResolvedValue(&amp;lt;mocked response&amp;gt;)&lt;/code&gt; to mock the response.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That's it!&lt;/p&gt;

&lt;p&gt;Here's what our test looks like after doing this:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="c1"&gt;// index.test.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getFirstAlbumTitle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./index&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;axios&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;axios&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;jest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;axios&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;returns the title of the first album&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mockResolvedValue&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;My First Album&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Album: The Sequel&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getFirstAlbumTitle&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toEqual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;My First Album&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;



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

&lt;/div&gt;
&lt;h2&gt;
  
  
  What's going on here?
&lt;/h2&gt;

&lt;p&gt;Let's break this down. The most important part to understand here is the import and &lt;code&gt;jest.mock()&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;axios&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;axios&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;jest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;axios&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


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

&lt;/div&gt;
&lt;p&gt;When you import a module into a test file, then call it in &lt;code&gt;jest.mock(&amp;lt;module-name&amp;gt;)&lt;/code&gt;, you have complete control over all functions from that module, &lt;em&gt;even if they're called inside another imported function&lt;/em&gt;. Immediately after calling &lt;code&gt;jest.mock('axios')&lt;/code&gt;, Jest replaces every function in the axios module with empty "mock" functions that essentially do nothing and return &lt;code&gt;undefined&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;axios&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;axios&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;jest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;axios&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// Does nothing, then returns undefined:&lt;/span&gt;
&lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://www.google.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// Does nothing, then returns undefined:&lt;/span&gt;
&lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.typicode.com/albums&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Album with a Vengeance&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;


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

&lt;/div&gt;
&lt;p&gt;So now that you've eliminated the default behavior, you can replace it with your own...&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

  &lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mockResolvedValue&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;My First Album&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Album: The Sequel&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;



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

&lt;/div&gt;
&lt;p&gt;The mocked replacement functions that Jest inserted into &lt;code&gt;axios&lt;/code&gt; happen to come with a whole bunch of cool superpower methods to control their behavior! The most important one here, for the purposes of a simple beginner mock, is &lt;code&gt;.mockResolvedValue()&lt;/code&gt;. When you call this on a mocked method, anything you pass in will be the default return value when the mocked function is called for the remainder of the test. Simply put: you can make &lt;code&gt;axios.get()&lt;/code&gt; return whatever you want! And &lt;strong&gt;it doesn't matter whether it's called directly in your test file or as a part of a function imported into your test&lt;/strong&gt; – Jest will mock the function no matter where it's called!&lt;/p&gt;

&lt;p&gt;Use this newfound power to give your functions exactly what they should expect from the API calls. Stop worrying about what the network requests return, and just focus on what YOUR code does once it gets the response!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you want to play around with the examples, feel free to use this demo repository:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&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%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/ZakLaughton" rel="noopener noreferrer"&gt;
        ZakLaughton
      &lt;/a&gt; / &lt;a href="https://github.com/ZakLaughton/DEMO-simple-api-mocking-with-jest" rel="noopener noreferrer"&gt;
        DEMO-simple-api-mocking-with-jest
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A simple API mocking example with Jest.
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;



&lt;h2&gt;
  
  
  Wrapping up
&lt;/h2&gt;

&lt;p&gt;There you have it! This is the very basics of what you need to mock functions from another module: &lt;strong&gt;import the module, &lt;code&gt;jest.mock()&lt;/code&gt; the module, then insert your own return values with &lt;code&gt;.mockResolvedValue()&lt;/code&gt;!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I recommend starting here, using &lt;em&gt;only&lt;/em&gt; these techniques as you start building out your first mocks for your network calls. Once you have a foundational understanding of what's going on here, you can slowly start adding the other robust mocking features included in Jest.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;See also: &lt;a href="https://jestjs.io/docs/en/mock-functions#mocking-modules" rel="noopener noreferrer"&gt;Mocking Modules&lt;/a&gt; (Jest documentation).&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;EDIT:&lt;/strong&gt; Also, be sure to clear your mocks between tests by running &lt;a href="https://jestjs.io/docs/en/jest-object#jestresetallmocks" rel="noopener noreferrer"&gt;&lt;code&gt;jest.resetAllMocks()&lt;/code&gt;&lt;/a&gt; after each test. This will help ensure your mocks won't interfere with future tests. (Thanks for pointing this out,  &lt;a href="https://dev.to/mjeffe/comment/1238h"&gt;@mjeffe&lt;/a&gt;!)&lt;/p&gt;




&lt;h2&gt;
  
  
  Where to go from here
&lt;/h2&gt;

&lt;p&gt;Alright, you've learned the basics of mocking and successfully implemented the strategies above in several tests. You can import and mock resolved values for all your API calls like an old pro. What's next?&lt;/p&gt;

&lt;p&gt;While the methods described above will cover most simple use cases, Jest has a lot of mocking functionality and methods to do some really powerful things. You can incrementally add some of the concepts below to super-charge your mocks:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Check out the other mock function methods listed in the Jest docs: &lt;a href="https://jestjs.io/docs/en/mock-function-api" rel="noopener noreferrer"&gt;Mock Functions&lt;/a&gt;. You can use methods such as &lt;code&gt;mockReturnedValue()&lt;/code&gt; to mock synchronous returns and &lt;code&gt;mockResolvedValueOnce()&lt;/code&gt; to only return a value the first time it's called.&lt;/li&gt;
&lt;li&gt;Want to see how many times a mocked function is called, what it was called with, and what it returned? Check out the &lt;code&gt;mock.calls&lt;/code&gt; and &lt;code&gt;mock.results&lt;/code&gt; properties (also in the &lt;a href="https://jestjs.io/docs/en/mock-function-api" rel="noopener noreferrer"&gt;Mock Functions documentation&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Do you have your own custom functions that make network requests? You can mock your own modules too after they're imported into the test file: &lt;code&gt;jest.mock('./path/to/js/module/file')&lt;/code&gt;! Careful here though that you're only mocking what's necessary. Your tests should make sure your functions do what's expected with a given mock input, and it can be easy to end up writing tests that instead just confirm you passed in mocked data.&lt;/li&gt;
&lt;li&gt;Want a function to act as it was originally written, but still want to see how many times it was called? Check out &lt;a href="https://jestjs.io/docs/en/jest-object#jestspyonobject-methodname" rel="noopener noreferrer"&gt;jest.spyOn()&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Find yourself mocking the same function over and over in multiple tests? Give it default mock responses in &lt;code&gt;__mocks__&lt;/code&gt; folders using &lt;a href="https://jestjs.io/docs/en/manual-mocks" rel="noopener noreferrer"&gt;Manual Mocks&lt;/a&gt;!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I hope this saves others some of the wasted time and frustration I went through! If anything doesn't make sense here, please leave a comment and I'd be happy to try to answer any questions. Also, let me know if there's anything else that helped you have an "Aha!" moment while learning to mock!&lt;/p&gt;




&lt;center&gt;_Did you find this this article useful? Feel free to subscribe to my articles below or [follow me on Twitter](https://twitter.com/ZakLaughton) for more developer tips and article announcements!_&lt;/center&gt;






</description>
      <category>testing</category>
      <category>jest</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Get data from your URL into your React app with React Router</title>
      <dc:creator>Zak Laughton</dc:creator>
      <pubDate>Fri, 27 Sep 2019 14:44:04 +0000</pubDate>
      <link>https://dev.to/zaklaughton/get-data-from-your-url-into-your-react-app-with-react-router-4def</link>
      <guid>https://dev.to/zaklaughton/get-data-from-your-url-into-your-react-app-with-react-router-4def</guid>
      <description>&lt;p&gt;In trying to learn React Router URL parameters, I had a hard time finding clean, no-frills examples. Now that I have a better understanding, I'm putting a plain, dead-simple example here to help others.&lt;/p&gt;

&lt;h2&gt;
  
  
  The end product
&lt;/h2&gt;

&lt;p&gt;I am going to show you how to create a site that takes 3 parameters from the URL, and passes them into a React component to display on the 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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Faud5i8jxld8dir3o7k6z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Faud5i8jxld8dir3o7k6z.png" alt="final website screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Basic understanding of building with &lt;a href="https://reactjs.org/" rel="noopener noreferrer"&gt;React&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;A react project with &lt;a href="https://www.npmjs.com/package/react-router-dom" rel="noopener noreferrer"&gt;react-router-dom&lt;/a&gt; installed (&lt;a href="https://github.com/facebook/create-react-app" rel="noopener noreferrer"&gt;Create React App&lt;/a&gt; is a great tool to spin up a React application)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The code
&lt;/h2&gt;

&lt;p&gt;This is the full index.js file, and pretty much everything you need to set up the site (see the full repository &lt;a href="https://github.com/zlaughton/dead-simple-routing-example" rel="noopener noreferrer"&gt;here&lt;/a&gt;):&lt;/p&gt;

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

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ReactDOM&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-dom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;BrowserRouter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Route&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-router-dom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;AppRouter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;BrowserRouter&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Route&lt;/span&gt;
      &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/:parameter1/:parameter2/:parameter3&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
      &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="p"&gt;{...&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;}
&lt;/span&gt;    &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/BrowserRouter&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;parameter1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;parameter2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;parameter3&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;match&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="na"&gt;First&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;parameter1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;br&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="na"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;parameter2&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;br&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="na"&gt;Third&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;parameter3&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;br&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;AppRouter&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  What's going on here?
&lt;/h2&gt;

&lt;p&gt;We're basically wrapping the entire application in a &lt;code&gt;&amp;lt;BrowserRouter&amp;gt;&lt;/code&gt; component, calling a &lt;code&gt;&amp;lt;Route&amp;gt;&lt;/code&gt; component for a given URL, and passing the parameters from the URL into &lt;code&gt;&amp;lt;App&amp;gt;&lt;/code&gt; as props. Lets dig into each piece…&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;code&gt;&amp;lt;BrowserRouter&amp;gt;&lt;/code&gt;
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;AppRouter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;BrowserRouter&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/BrowserRouter&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;In order to use &lt;code&gt;&amp;lt;Route&amp;gt;&lt;/code&gt;, it must have &lt;code&gt;&amp;lt;BrowserRouter&amp;gt;&lt;/code&gt; (or one of the other router types) somewhere as a parent. React Router uses this &lt;a href="https://reactjs.org/docs/higher-order-components.html" rel="noopener noreferrer"&gt;higher order component&lt;/a&gt; to help do its routing magic in the background. There's no component configuration required here – all you need to do is be sure everything is wrapped in &lt;code&gt;&amp;lt;BrowserRouter&amp;gt;&lt;/code&gt; open/close tags.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://reacttraining.com/react-router/web/api/BrowserRouter" rel="noopener noreferrer"&gt;&lt;code&gt;&amp;lt;BrowserRouter&amp;gt;&lt;/code&gt; documentation&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;&amp;lt;Route&amp;gt;&lt;/code&gt;
&lt;/h3&gt;

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

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Route&lt;/span&gt;
  &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/:parameter1/:parameter2/:parameter3&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="p"&gt;{...&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;}
&lt;/span&gt;&lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Here's where the meat of the work is being done.  is a component that decides what component to show based on the URL.&lt;br&gt;
path='/:parameter1/:parameter2/:parameter3' tells React Router to use this  component whenever the URL has a path with 3 items separated by slashes after the base URL (for example, tvshows.com/series/season/episode). The parameters, such as :parameter1, are variables to assign that part of the URL to and pass into the rendered component.&lt;br&gt;
render={props =&amp;gt; }renders the  component with the props passed in from the route, which will include the parameters set in the path in the line above&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://reacttraining.com/react-router/web/api/Route" rel="noopener noreferrer"&gt;&lt;code&gt;&amp;lt;Route&amp;gt;&lt;/code&gt; documentation&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;&amp;lt;App&amp;gt;&lt;/code&gt;
&lt;/h3&gt;

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

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;parameter1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;parameter2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;parameter3&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;match&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="na"&gt;First&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;parameter1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;br&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="na"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;parameter2&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;br&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="na"&gt;Third&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;parameter3&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;br&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Since &lt;code&gt;&amp;lt;Route&amp;gt;&lt;/code&gt; is rendering this &lt;code&gt;&amp;lt;App&amp;gt;&lt;/code&gt; component, it's also passing in the props it needs. &lt;code&gt;&amp;lt;Route&amp;gt;&lt;/code&gt; passes several props by default, but the one part of the props we're concerned about here is match.params. &lt;strong&gt;Whenever you use &lt;code&gt;&amp;lt;Route&amp;gt;&lt;/code&gt; to render a component, you can always find the URL parameters in props.match.params.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;&amp;lt;App&amp;gt;&lt;/code&gt; component uses &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment" rel="noopener noreferrer"&gt;object destructuring&lt;/a&gt; to assign local variables for all the parameters passed in props.match.params, then uses these variables to display the data from the URL. That's it!&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping up
&lt;/h2&gt;

&lt;p&gt;Once you get the hang of using URL parameters, you can do some pretty powerful things with rendering the application based on the exact URL the user is visiting. It's even a handy way to &lt;a href="https://reactjs.org/docs/lifting-state-up.html" rel="noopener noreferrer"&gt;lift up state&lt;/a&gt; in certain cases where you have multiple lower-level components sharing the same state that's also reflected in the URL.&lt;/p&gt;

&lt;p&gt;Questions? Comments? Concerns? Let me know! Comment below or tweet me &lt;a href="https://twitter.com/ZakLaughton" rel="noopener noreferrer"&gt;@ZakLaughton&lt;/a&gt;.&lt;/p&gt;




&lt;center&gt;_Did you find this this article useful? Feel free to subscribe to my articles below or [follow me on Twitter](https://twitter.com/ZakLaughton) for more developer tips and article announcements!_&lt;/center&gt;






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