<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Kasper Fabricius Kristensen</title>
    <description>The latest articles on Forem by Kasper Fabricius Kristensen (@kasperkristensen).</description>
    <link>https://forem.com/kasperkristensen</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%2F700289%2F522e6aad-b7af-486c-85c0-119a1a19c4c2.jpeg</url>
      <title>Forem: Kasper Fabricius Kristensen</title>
      <link>https://forem.com/kasperkristensen</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/kasperkristensen"/>
    <language>en</language>
    <item>
      <title>Create An Open Source Ecommerce Store with Gatsby and Medusa</title>
      <dc:creator>Kasper Fabricius Kristensen</dc:creator>
      <pubDate>Tue, 29 Mar 2022 15:56:19 +0000</pubDate>
      <link>https://forem.com/medusajs/create-an-open-source-ecommerce-store-with-gatsby-and-medusa-2h6b</link>
      <guid>https://forem.com/medusajs/create-an-open-source-ecommerce-store-with-gatsby-and-medusa-2h6b</guid>
      <description>&lt;p&gt;&lt;a href="https://www.medusajs.com/" rel="noopener noreferrer"&gt;Medusa&lt;/a&gt; is an open source headless commerce platform that’s focused on providing a great developer experience while creating an ecommerce store.&lt;/p&gt;

&lt;p&gt;Using Medusa’s headless architecture, you can create a storefront with any programming language or framework you prefer just by connecting it to the REST APIs. Your storefront will be able to display products and will have the full ecommerce checkout workflow.&lt;/p&gt;

&lt;p&gt;In this tutorial, you’ll learn how to connect our Gatsby starter to your Medusa server.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb287nxim2zu31hj4w3oc.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%2Fuploads%2Farticles%2Fb287nxim2zu31hj4w3oc.png" alt="Front page of the Gatsby Starter"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Features
&lt;/h2&gt;

&lt;p&gt;The Gatsby storefront comes with a lot of features out of the box, here are some of them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;View all products and manage your cart.&lt;/li&gt;
&lt;li&gt;Customer authentication.&lt;/li&gt;
&lt;li&gt;Full checkout workflow.&lt;/li&gt;
&lt;li&gt;Request swaps and returns using a customer’s order ID and Email.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;This article assumes you already have a Medusa server installed. If you don’t you can follow &lt;a href="https://docs.medusajs.com/quickstart/quick-start" rel="noopener noreferrer"&gt;this quickstart guide&lt;/a&gt; to get you started in minutes.&lt;/p&gt;

&lt;p&gt;You also need to have the Gatsby CLI tool installed as you’ll be using it to create the Gatsby store. You can install it with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; gatsby-cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create Gatsby Storefront
&lt;/h2&gt;

&lt;p&gt;In your terminal, run the following command to create the Medusa storefront with Gatsby:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gatsby new my-medusa-store https://github.com/medusajs/gatsby-starter-medusa
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a Gatsby website using the already-existing &lt;a href="https://github.com/medusajs/gatsby-starter-medusa" rel="noopener noreferrer"&gt;Medusa Gatsby starter&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Set Environment Variables
&lt;/h3&gt;

&lt;p&gt;To connect to the backend, you need to set the URL that leads to the backend in the environment variables.&lt;/p&gt;

&lt;p&gt;The Gatsby starter comes with the file &lt;code&gt;.env.template&lt;/code&gt; that you can use to add your environment variables. First, rename the file:&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;mv&lt;/span&gt; .env.template .env.development
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This changes the name to &lt;code&gt;.env.development&lt;/code&gt;. You can also rename it to &lt;code&gt;.env.production&lt;/code&gt; for production use, or just rename it to &lt;code&gt;.env&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This file includes 2 environment variables:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;GATSBY_MEDUSA_BACKEND_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;http://localhost:9000
&lt;span class="nv"&gt;GATSBY_STRIPE_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;pk_test_something
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first one is the URL to the Medusa server. By default, the Medusa server runs on &lt;code&gt;localhost:9000&lt;/code&gt;. So, if you didn’t change that you can leave it as is.&lt;/p&gt;

&lt;p&gt;The second one is your Stripe public key if you have Stripe set up. If you don’t, you can leave it as is.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test it Out
&lt;/h2&gt;

&lt;p&gt;Before you run your storefront make sure that your Medusa server is running.&lt;/p&gt;

&lt;p&gt;Then, in your terminal in your Gatsby storefront, start the storefront with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The storefront should run on &lt;code&gt;localhost:8000&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%2Fuploads%2Farticles%2Frw9n11u6a1ef8mt6xu8x.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%2Fuploads%2Farticles%2Frw9n11u6a1ef8mt6xu8x.png" alt="Product page in the Gatsby Starter"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Note About Development
&lt;/h2&gt;

&lt;p&gt;It’s worth noting that the Gatsby starter makes use of the &lt;a href="https://github.com/medusajs/medusa/tree/master/packages/gatsby-source-medusa" rel="noopener noreferrer"&gt;&lt;code&gt;gatsby-source-medusa&lt;/code&gt;&lt;/a&gt; plugin to source data from your Medusa server. This data includes products, collections and regions, and as a result, you are able to query this data in the starter using GraphQL queries. You can also explore the data in your store on &lt;code&gt;localhost:8000/___graphql&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;As a result of this, you will need to rebuild the site every time you update any of this data for it to be reflected in your storefront. We will soon be releasing a new version of the plugin which adds incremental builds, which will improve build times, but more on that at a later time.&lt;/p&gt;

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

&lt;p&gt;In this tutorial, you learned how to get a Gatsby store up and running. Your storefront includes products listing, cart management, checkout workflow, an option for customers to request returns and exchanges for their previous orders, customer login, and customer order history.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Should you have any issues or questions related to Medusa, then feel free to reach out to the Medusa team via &lt;a href="https://discord.gg/F87eGuwkTp" rel="noopener noreferrer"&gt;Discord&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>javascript</category>
      <category>opensource</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
