<?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: Ankit</title>
    <description>The latest articles on Forem by Ankit (@a9kitkumar).</description>
    <link>https://forem.com/a9kitkumar</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%2F134421%2F19b61d46-2aef-4851-9377-9e534934472c.jpeg</url>
      <title>Forem: Ankit</title>
      <link>https://forem.com/a9kitkumar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/a9kitkumar"/>
    <language>en</language>
    <item>
      <title>How to Build a JAMstack Website using Vue.js, Nuxt.js and Cosmic JS</title>
      <dc:creator>Ankit</dc:creator>
      <pubDate>Tue, 18 Jun 2019 16:23:23 +0000</pubDate>
      <link>https://forem.com/a9kitkumar/how-to-build-a-jamstack-website-using-vue-js-nuxt-js-and-cosmic-js-l62</link>
      <guid>https://forem.com/a9kitkumar/how-to-build-a-jamstack-website-using-vue-js-nuxt-js-and-cosmic-js-l62</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7IVFSiq9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.cosmicjs.com/6ca5f420-912a-11e9-bc00-5fc34b01c111-68747470733a2f2f636f736d69632d73332e696d6769782e6e65742f39633962376633302d393132332d313165392d616636352d3935653930663332323632382d6e7578742d6a616d737461636b2e706e67.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7IVFSiq9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.cosmicjs.com/6ca5f420-912a-11e9-bc00-5fc34b01c111-68747470733a2f2f636f736d69632d73332e696d6769782e6e65742f39633962376633302d393132332d313165392d616636352d3935653930663332323632382d6e7578742d6a616d737461636b2e706e67.png" alt="Folder Structure" width="880" height="505"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this tutorial, we are building a JAMstack website with Cosmic JS. Let's first define our JAMstack: 'J' stands for JavaScript, our application uses Vue.js. 'A' stands for APIs, and we are using the powerful APIs of &lt;a href="https://cosmicjs.com/"&gt;Cosmic JS&lt;/a&gt;. 'M' stands for Markup, which is Nuxt.js in this example. For this tutorial, we will be building a simple fitness studio website. In the end, we will deploy it on Netlify which gives serverless backend services and hosting. Let's get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://cosmicjs.com/apps/jamstack-fitness-website"&gt;Checkout the demo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/cosmicjs/nuxt-jamstack-website"&gt;Download the codebase&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;We are building a JAMstack website with the powerful APIs of Cosmic JS. This website is about fitness and the body.  The first page is dynamic with some navigations provided by Vue.js. On the left side navigation, you will find the link to the blog, whose data is also coming from the Cosmic JS via the Cosmic JS APIs. Let's start now with the requirements.&lt;/p&gt;

&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;p&gt;The one and the only requirement is &lt;a href="https://nodejs.org/en/"&gt;Node.js&lt;/a&gt;. Install it on your system to run npm commands. &lt;/p&gt;

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

&lt;p&gt;Here we are using npm but you can also use yarn to install packages. So if you have installed above software, run the following command to a quick start:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;npx create-nuxt-app jamstack_app&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Here jamstack_app is your desired name of the app. Now go to the root of the created folder, and run the following command to run it in development:&lt;/p&gt;

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

&lt;p&gt;Now visit: &lt;a href="http://localhost:3000/"&gt;http://localhost:3000/&lt;/a&gt; to view the project in development mode. &lt;/p&gt;

&lt;p&gt;Learn more about Nuxt.js quick starter kit here: &lt;a href="https://nuxtjs.org/guide/installation/"&gt;Nuxt.js Starter Kit&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Folder Structure
&lt;/h2&gt;

&lt;p&gt;After creating the app, you will get the same folder structure as given in the picture:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yJSlhPqf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.cosmicjs.com/b0f99950-8e01-11e9-8e40-370eb5e3d090-Screenshot-from-2019-06-13-23-02-43.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yJSlhPqf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.cosmicjs.com/b0f99950-8e01-11e9-8e40-370eb5e3d090-Screenshot-from-2019-06-13-23-02-43.png" alt="Folder Structure" width="427" height="483"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's explain the main folders and files of this structure. package.json file contains the record of all modules installed in your project. Static folder contains the static files used in the project like logo and images. Pages folder contains the pages like home page and blog etc. node_modules has all modules installed and layout contains styling of the project. Config folder is created by us to save the config.js file which will be used at the time dynamic requests to the Cosmic JS server. &lt;/p&gt;

&lt;h2&gt;
  
  
  Configuration
&lt;/h2&gt;

&lt;p&gt;We have generated the Nuxt.js app with the app generator but the main configuration is pending to make our app a complete JAMstack app. With the creation of the app, JavaScript and Markup part of the app completed. Now we are configuring the API part of the app that means the Cosmic JS part. &lt;/p&gt;

&lt;p&gt;For this, you need a Cosmic JS account. &lt;a href="https://cosmicjs.com/signup"&gt;Sign up for Cosmic JS&lt;/a&gt; official website, it is totally free. Then create a free bucket and create your first object type: 'blogs'. Or you can import a built-in bucket, way to import it is given in the below heading. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rR75OPBn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.cosmicjs.com/4c233670-8d35-11e9-9d53-0d7baf38376b-Screenshot-from-2019-06-12-22-41-16.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rR75OPBn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.cosmicjs.com/4c233670-8d35-11e9-9d53-0d7baf38376b-Screenshot-from-2019-06-12-22-41-16.png" alt="Folder Structure" width="880" height="498"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now click the basic setting option in your dashboard, it will open your basic setting page as shown above. Note down your bucket slug, bucket_id. Now generate the read and write keys and save them on your computer. Now save them in your project also. For this create a config folder and create a config.js file in it and save as given below:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  In-built Bucket
&lt;/h2&gt;

&lt;p&gt;If you don't want to create a new bucket, then you have an option to import a readymade bucket. For this, download the bucket.json file from our Git codebase and import it from your dashboard from the Import/Export option, check below image for visual help:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--quIsHVK1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.cosmicjs.com/b05f8a00-8d42-11e9-869f-cb5634810819-Screenshot-from-2019-06-13-00-16-34.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--quIsHVK1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.cosmicjs.com/b05f8a00-8d42-11e9-869f-cb5634810819-Screenshot-from-2019-06-13-00-16-34.png" alt="Folder Structure" width="880" height="583"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Home Page
&lt;/h2&gt;

&lt;p&gt;Let's get started with the first page that is the home page. In this we will render the dynamic data from Cosmic JS server with APIs, it will show you the Vue.js part of the website. Here we are going to write the detail of our website and will implement navigation in the header of the website as well as in the bottom part will give a button to navigate to blog. Check out the code of homepage at location: &lt;em&gt;pages/index.vue&lt;/em&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;This page is a template plus vue.js code and pure dynamic in nature. Here we applied a link at the bottom which navigates to the blog page and this blog page is also pure dynamic in nature.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Layout of the Website
&lt;/h2&gt;

&lt;p&gt;The complete layout of the app is coded in a single file for good structure. Here we are customizing the header, footer and other color schemes of the app.  Check out the code for layout &lt;em&gt;layouts/default.vue&lt;/em&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Here we defined the body color of the website along with the header, footer, and navigational effects. In the navigation, we have given route to blog page and route to the home page as well. In the header of the app, we have given navigation to home to the title of the website. &lt;/p&gt;

&lt;h2&gt;
  
  
  Blog Page
&lt;/h2&gt;

&lt;p&gt;This is the second page of our website, it handles the dynamic fetching of the data from Cosmic JS server with the help of Cosmic JS APIs. First of all, check the code and then we will explain it. Code is placed at the location: &lt;em&gt;pages/blog.vue&lt;/em&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;There are two part of the page, first is template and second if JavaScript part. In the template, we have given the route to the home page with the back button and rendered the title and body of the blog. &lt;/p&gt;

&lt;p&gt;In JavaScript part, we have made of a GET request to the Cosmic JS server with the help of Cosmic JS API. This API is the combination of the static URL, bucket slug and object type. In GET request, read key is necessary to get the data from the server. After a successful request, we manipulated the data and passed to variables as shown in the code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--r0u0qtO4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.cosmicjs.com/e066a130-8dff-11e9-bbbc-e3026215e4a7-Screenshot-from-2019-06-13-22-51-34.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--r0u0qtO4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.cosmicjs.com/e066a130-8dff-11e9-bbbc-e3026215e4a7-Screenshot-from-2019-06-13-22-51-34.png" alt="Folder Structure" width="880" height="440"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Static Folder
&lt;/h2&gt;

&lt;p&gt;In the codebase, check out the static folder. As the name describes, it contains the static data and in our case, it contains the static images of our project. As you know our front page id totally static, image shown on the front page resides in this folder. In the same way, any static image or logo which will be used in the project must be placed here. &lt;/p&gt;

&lt;h2&gt;
  
  
  What Have We Built?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7IVFSiq9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.cosmicjs.com/6ca5f420-912a-11e9-bc00-5fc34b01c111-68747470733a2f2f636f736d69632d73332e696d6769782e6e65742f39633962376633302d393132332d313165392d616636352d3935653930663332323632382d6e7578742d6a616d737461636b2e706e67.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7IVFSiq9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.cosmicjs.com/6ca5f420-912a-11e9-bc00-5fc34b01c111-68747470733a2f2f636f736d69632d73332e696d6769782e6e65742f39633962376633302d393132332d313165392d616636352d3935653930663332323632382d6e7578742d6a616d737461636b2e706e67.png" alt="Folder Structure" width="880" height="505"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have built a JAMstack website with the powerful APIs of Cosmic JS. In JAMstack:&lt;/p&gt;

&lt;p&gt;'J' stands for JavaScript and here Vue.js used as JavaScript part of JAM,&lt;br&gt;
'A 'stands for API, here Cosmic JS used as the API part of JAM,&lt;br&gt;
Meaning of 'M' is Markup, here Nuxt.js is used as the markup. &lt;br&gt;
Here the main part is the API part, we have made a GET request with the help of which and got the quick response. This request made with the help of axios module and then JSON data manipulated easily. Format of the Cosmic JS API response is very simple to handle. &lt;/p&gt;

&lt;h2&gt;
  
  
  Deployment to Netlify
&lt;/h2&gt;

&lt;p&gt;We have built an app with Vue.js, Nuxt.js, and Cosmic JS, but it is not a pure JAMstack app until we can deploy the static assets to a CDN. For this example, we will deploy it to the serverless backend service provider &lt;a href="https://www.netlify.com/"&gt;Netlify&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Install the &lt;a href="https://www.npmjs.com/package/netlify-cli"&gt;Netlify CLI&lt;/a&gt; and &lt;a href="https://www.npmjs.com/package/nuxt"&gt;Nuxt CLI&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;npm i -g netlify-cli&lt;br&gt;
npm i -g nuxt&lt;br&gt;
Build the static files&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;npm run build&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Then deploy to Netlify. You will be prompted to select the folder. Type dist to deploy the dist folder.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;netlify deploy&lt;/em&gt;&lt;/p&gt;

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

&lt;p&gt;With the help of Cosmic JS you can create powerful applications. In this example, we were able to build a JAMstack application with the API power of Cosmic JS. If you have any comments or questions about building apps with Cosmic JS, reach out to us on &lt;a href="https://twitter.com/cosmic_js"&gt;Twitter&lt;/a&gt; and join the conversation on &lt;a href="https://cosmicjs.com/community"&gt;Slack&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>cosmicjs</category>
      <category>vue</category>
      <category>nuxt</category>
      <category>jamstack</category>
    </item>
    <item>
      <title>How to build an Ecommerce Website using Gatsby and Cosmic JS</title>
      <dc:creator>Ankit</dc:creator>
      <pubDate>Wed, 01 May 2019 17:03:02 +0000</pubDate>
      <link>https://forem.com/a9kitkumar/how-to-build-an-ecommerce-website-using-gatsby-and-cosmic-js-3bbm</link>
      <guid>https://forem.com/a9kitkumar/how-to-build-an-ecommerce-website-using-gatsby-and-cosmic-js-3bbm</guid>
      <description>&lt;p&gt;This tutorial will show you how to build an e-commerce app using Gatsby and Cosmic JS. This app will give you a basic idea of how we can integrate an e-commerce app with Cosmic JS to store our data. In this app example, all order data will be stored in the Cosmic JS database and its speed will charm you. Let's get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://cosmicjs.com/apps/gatsby-ecommerce-website" rel="noopener noreferrer"&gt;Checkout the demo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/a9kitkumar/Gatsby-Ecommerce" rel="noopener noreferrer"&gt;Download the codebase&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction to the App
&lt;/h2&gt;

&lt;p&gt;Here we are building an e-commerce app in Gatsby with the backend power of Cosmic JS. We will make some navigation based on an e-commerce website and at the end placed order will be saved on the Cosmic JS database. Cosmic JS provides npm module for JavaScript technologies. Also, it provides API endpoints with the help of which you can directly apply CRUD operations on it. Here we are using API endpoints to store our data. &lt;/p&gt;

&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://nodejs.org/en/" rel="noopener noreferrer"&gt;Node.js&lt;/a&gt; must be installed on your system, it is required to run npm commands. Choose its latest version and install it on your system.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After node.js, install Gatsby CLI on your system globally. You can find it here: &lt;a href="https://www.gatsbyjs.org/docs/gatsby-cli/" rel="noopener noreferrer"&gt;Gatsby CLI&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Recommended post: &lt;a href="https://mytechmarvel.com/snapchat-cheating-how-to-know-if-your-partner-is-cheating/" rel="noopener noreferrer"&gt;Snapchat Cheating: How to Catch a Snapchat Cheater?&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Let’s Get Started
&lt;/h2&gt;

&lt;p&gt;We assumed that you have installed the above software and CLI. Now run the following command to create a new Gatsby app:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;gatsby new Gatsby-Ecommerce&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;After executing this command successfully, it is ensured that you have created a new Gatsby app with the name "Gatsby-Ecommerce". Now to start this, execute the following command from the terminal:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;npm start&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It will run your app and opens the port: &lt;a href="http://localhost:8000/" rel="noopener noreferrer"&gt;http://localhost:8000/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Configuration with Cosmic JS
&lt;/h2&gt;

&lt;p&gt;Cosmic JS is two in one service provider that means it gives the facility of database and server as well. So you need to signup for &lt;a href="https://cosmicjs.com/" rel="noopener noreferrer"&gt;Cosmic JS&lt;/a&gt; first and create a new bucket with any name you want, here we created the bucket with the name Gatsby Ecommerce. Now it is time to create an object type, which means to the data management. Create object type named orders, All orders will be stored in this object. Now we have to do some basic setting, for this goto basic setting in your dashboard. Have a look at the below screenshot:&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%2Fcosmic-s3.imgix.net%2F379480e0-6c30-11e9-ac17-d1d41ed61c71-67fc1480-6ab1-11e9-8e11-73687f4b8132-basic-setting.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%2Fcosmic-s3.imgix.net%2F379480e0-6c30-11e9-ac17-d1d41ed61c71-67fc1480-6ab1-11e9-8e11-73687f4b8132-basic-setting.png" alt="Basic setting"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here you can see the read/write keys fields and other IDs. Click on generate read and write keys and save on any text file along with bucket ID and slug. &lt;/p&gt;

&lt;p&gt;Now open your Gatsby project in any IDE, here I'm using Visual Basic Code. Now create a folder named config in root od the project and create a new file with name config.js inside the config folder and save the above IDs and keys in the following format:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;It is important for you to manage your project properly, so have a look at the screenshot of the folder structure of the project:&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%2Fcosmic-s3.imgix.net%2Fef424b00-6c30-11e9-ac17-d1d41ed61c71-4919a090-6ab2-11e9-82e0-8508380770be-folder-structure.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%2Fcosmic-s3.imgix.net%2Fef424b00-6c30-11e9-ac17-d1d41ed61c71-4919a090-6ab2-11e9-82e0-8508380770be-folder-structure.png" alt="Folder Structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Inbuilt Bucket
&lt;/h2&gt;

&lt;p&gt;You can also use an inbuilt bucket. For this, you have to import that inbuilt bucket in your Cosmic JS account. Here we are providing our bucket for you. You just need to follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to our &lt;a href="https://github.com/a9kitkumar/Gatsby-Ecommerce" rel="noopener noreferrer"&gt;Git repo&lt;/a&gt; and download the bucket.json file&lt;/li&gt;
&lt;li&gt;Now go to your Cosmic JS dashboard and click on basic settings&lt;/li&gt;
&lt;li&gt;Click on Import/Export and click on Add import file, and import the bucket.json file&lt;/li&gt;
&lt;/ol&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%2Fcosmic-s3.imgix.net%2F415be6d0-6c31-11e9-a9e2-17ca88838afb-f8070290-6ab3-11e9-8e11-73687f4b8132-import-export-file.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%2Fcosmic-s3.imgix.net%2F415be6d0-6c31-11e9-a9e2-17ca88838afb-f8070290-6ab3-11e9-8e11-73687f4b8132-import-export-file.png" alt="Import Export"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now everything is ready, we can move to implement our app now&lt;/p&gt;

&lt;h2&gt;
  
  
  Home Page
&lt;/h2&gt;

&lt;p&gt;Now we are going to build our app, and the main page is the home page. On this page, we will show the items for shopping. We will add a few items as this app will only show you the compatibility of Gatsby e-commerce app with Cosmic JS. Location of the home component is &lt;em&gt;src/components/home.js&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Check the code of the home component, then we will explain it.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;This component is stateful, not a stateless component as most of the Gatsby components usually are. &lt;/p&gt;

&lt;p&gt;In this component, we have shown three products which all are iPhones. Main this is that images of these iPhones are kept in a folder and called through a different component. At line number 91, 94, and 97 you can check how these are imported to home. &lt;/p&gt;

&lt;p&gt;Here we used the bootstrap modal to show the specifications of the products. Let us explain the working of the main methods.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;addToCart()&lt;/strong&gt;: This is an event-driven method and pushes the product to an array when the user clicks on the add to cart. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;handleiPhone8Close()&lt;/strong&gt; and &lt;strong&gt;handleiPhone8Show()&lt;/strong&gt;: These are the handlers for bootstrap modals which are used to show the specifications of products. &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%2Fcosmic-s3.imgix.net%2Fb80c9360-6c31-11e9-ba78-f3011d5454ef-8d0f69d0-6b64-11e9-8c29-39fe44eff7e3-home-page.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%2Fcosmic-s3.imgix.net%2Fb80c9360-6c31-11e9-ba78-f3011d5454ef-8d0f69d0-6b64-11e9-8c29-39fe44eff7e3-home-page.png" alt="Home"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  iPhones Component
&lt;/h2&gt;

&lt;p&gt;The iPhone folder has three components named iphone8.js, iphonex.js, and iphonexs.js. These components only used to add images to other components. We used these components in home page. Actually, these components use   for this purpose which makes the images loading very fast on websites. Check the code of one image component: &lt;em&gt;components/iPhones/iphone8.js&lt;/em&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  Cart Component
&lt;/h2&gt;

&lt;p&gt;When the user added products to the cart and click the Show Cart button, then flow of the app goes to another page cart.js. Let's check the code of this page: &lt;em&gt;src/pages/cart.js&lt;/em&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Let us explain each method of cart.js:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;getProducts()&lt;/strong&gt;: In this method, we are getting the products which are stored in the cart. For cart, we temporary stores the products in local storage. That means this method is getting the products from local storage. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;checkingCart()&lt;/strong&gt;: This method is checking that which product is added to the cart that means this method is filtering the products and calculating the price. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;onSubmit()&lt;/strong&gt;: This is an event-driven method, which collecting the details of the order along with user billing details and passing to the method placeOrder() in the cosmicService.&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%2Fcosmic-s3.imgix.net%2F523943c0-6c32-11e9-8d98-25edff7d0d98-f8654cf0-6b68-11e9-8c29-39fe44eff7e3-place-order.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%2Fcosmic-s3.imgix.net%2F523943c0-6c32-11e9-8d98-25edff7d0d98-f8654cf0-6b68-11e9-8c29-39fe44eff7e3-place-order.png" alt="Home"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Cosmic Service
&lt;/h2&gt;

&lt;p&gt;This is the only service in this app which hits the Cosmic JS API and stores the data to Cosmic JS database. Check the code: &lt;em&gt;src/services/cosmicService.js&lt;/em&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;There is only one method in this service named placeOrder() which accepts the seven arguments. It hits the post request to the Cosmic JS server to save the data. Here we are providing write access key for taking the permission of writing on the Cosmic JS database. This is an example of storing information in Cosmic JS; however, it's never advised to store credit card data in Cosmic JS. &lt;/p&gt;

&lt;h2&gt;
  
  
  What Functionality We Have Implemented?
&lt;/h2&gt;

&lt;p&gt;Till now we have implemented the complete functionality on the development server. That means we can use the complete functionality of the app in development mode. Because it is a Gatsby app created with npm CLI, so it is deployable on any server which allows deployment from node.js app. Here we deployed our app on Heroku server.&lt;/p&gt;

&lt;p&gt;We created this app with Gatsby CLI and used React.js also to make some components stateful. After using this app, you will understand the power of Cosmic JS because of its blazing speed. &lt;/p&gt;

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

&lt;p&gt;With the help of Cosmic JS we can create powerful apps and can use the Cosmic JS database for fast data processing. Here we created and configured a Gatsby.js app with Cosmic JS without any difficulty. You don't need to install any extra efforts to configure and use Cosmic JS APIs.&lt;/p&gt;

&lt;p&gt;For any query or comment related to building apps in Cosmic JS, reach out to us on &lt;a href="https://twitter.com/cosmic_js" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; and join the conversation on &lt;a href="https://cosmicjs.com/community" rel="noopener noreferrer"&gt;Slack&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>gatsby</category>
      <category>cosmicjs</category>
      <category>ecommerce</category>
    </item>
    <item>
      <title>How to Build a PWA in React.js and Cosmic JS</title>
      <dc:creator>Ankit</dc:creator>
      <pubDate>Tue, 05 Feb 2019 17:53:58 +0000</pubDate>
      <link>https://forem.com/a9kitkumar/how-to-build-a-pwa-in-reactjs-and-cosmic-js-25k9</link>
      <guid>https://forem.com/a9kitkumar/how-to-build-a-pwa-in-reactjs-and-cosmic-js-25k9</guid>
      <description>&lt;p&gt;In this tutorial I will show you how to build a progressive web app using React.js and &lt;a href="https://cosmicjs.com/" rel="noopener noreferrer"&gt;Cosmic JS&lt;/a&gt;. Our PWA will respond with status 200 when you are offline. The app will attain the last state of data and display it to you when you are offline. We will start with the basics and complete the app in full details. After completion we will deploy it to the Cosmic JS App Server, so let's get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://cosmicjs.com/apps/react-pwa-with-authentication" rel="noopener noreferrer"&gt;Checkout the demo&lt;/a&gt;&lt;br&gt;
Admin Credentials:&lt;br&gt;
email: &lt;a href="mailto:admin@abc.com"&gt;admin@abc.com&lt;/a&gt;&lt;br&gt;
password: admin&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/cosmicjs/react-pwa" rel="noopener noreferrer"&gt;Download the codebase&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What are We Building?
&lt;/h2&gt;

&lt;p&gt;As the title explained we are building a progressive web app (PWA) which will display news published by an admin. Let's start by explaining what a PWA is in simple words:&lt;/p&gt;

&lt;p&gt;A PWA is a ordinary website that has some extra and unique features which make it extraordinary. Here are those features:&lt;/p&gt;

&lt;p&gt;-&amp;gt; You can use these apps while you are offline, that means these apps give a response code 200 while internet is disconnected&lt;br&gt;
-&amp;gt; Second most important feature is that you can install it on your device ( either desktop or mobile )&lt;br&gt;
-&amp;gt; These apps are fully responsive in nature&lt;br&gt;
We will be implementing this app using React.js with the power of Cosmic JS. Let's start.&lt;/p&gt;

&lt;p&gt;Also Read: &lt;a href="https://mytechmarvel.com/best-phone-tracker-app-without-permission/" rel="noopener noreferrer"&gt;Best Phone Tracker App Without Permission&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://nodejs.org/en/" rel="noopener noreferrer"&gt;Node.js&lt;/a&gt; must be installed on your system to to run npm commands, with the help of which we will install react app. For more information, you can refer to &lt;a href="https://reactjs.org/docs/getting-started.html" rel="noopener noreferrer"&gt;React Docs&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;p&gt;Now that our system is configured with the required modules and tools, we are going to create a progressive web app project in React.js using Cosmic JS. Go to your any specific folder where you want to place your project and open console (terminal) and type the following command:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;npx create-react-app react-pwa&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;here react-pwa is the name of your app and then goto created folder react-pwa and run command:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;npm start&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It will compile your basic React.js app and automatically opens in default browser. By default it runs on the port number 3000: &lt;a href="http://localhost:3000/" rel="noopener noreferrer"&gt;http://localhost:3000/&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Configure React App with Cosmic JS
&lt;/h2&gt;

&lt;p&gt;Till now, we have just implemented the front-end part of the PWA, now it is time to configure the server i.e. Cosmic JS server and database. It gives two in one facility. &lt;/p&gt;

&lt;p&gt;First of all, &lt;a href="https://cosmicjs.com/signup" rel="noopener noreferrer"&gt;signup on Cosmic JS&lt;/a&gt;  for free and create your first Bucket. Now create an Object-Type, which in our case is Admin. Similarly create two more object types named 1) News and 2) Comments. These three object types have different purposes: Admin will save the credentials of admin, News will save the news published by admin and Comments will save the comments posted by users. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv9nxsnenntwvehgco4vy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv9nxsnenntwvehgco4vy.png" alt="Basic setting" width="800" height="490"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now go to &lt;em&gt;Settings &amp;gt; Basic Settings&lt;/em&gt; and generate read_key as well as write_key, and save all information of this page in a separate file on your system. Now place all of this information in the folder of your project and path will be: &lt;em&gt;src&amp;gt;config&amp;gt;config.js&lt;/em&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;To manage your project properly, you should create different folders for components, services, config files, css and images. It will help any third person to understand your code properly. All of these folders should reside in src folder. So create them first and jump to next step.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ready Made Bucket
&lt;/h2&gt;

&lt;p&gt;For this project you can directly import a bucket to your dashboard, in that bucket we have already created object-types. You have to download bucket.json from our &lt;a href="https://github.com/cosmicjs/react-pwa" rel="noopener noreferrer"&gt;git repo&lt;/a&gt; and then just follow the steps: Choose default bucket &amp;gt; Go to Settings &amp;gt; go to Import / Export and click the button "Add import file". It will import the bucket.json file. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3en3c2j1479nzx64vd6b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3en3c2j1479nzx64vd6b.png" alt="Basic setting" width="800" height="484"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here we have created the platform to implement our PWA, so let's move to the next one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Admin Login
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7iqb2rrpdde0ncsri40j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7iqb2rrpdde0ncsri40j.png" alt="Basic setting" width="800" height="481"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In our bucket, there is an object-type "Admin". Create an object with title admin, and metafields email &amp;amp; password. You can give the values of email and passwords according to you. Here we gave email: &lt;a href="mailto:admin@abc.com"&gt;admin@abc.com&lt;/a&gt; and password: admin. Later you can use them for admin login in our demo. &lt;/p&gt;

&lt;p&gt;Create a login page for admin in &lt;em&gt;src&amp;gt;components&amp;gt;login.js&lt;/em&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;On this page we are simply logging the admin in. We have statically created the email and password in the object-type "admin" and with those credentials we are logging him in. Here we imported the authentication service and in the onSubmit() function we are calling the login() function which is declared in the authentication service. In componentDidMount() we simply applied navigation when admin already logged in.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dashboard Component
&lt;/h2&gt;

&lt;p&gt;In this component we simply displayed the three links: Home, Add News and Logout. From here admin can navigate to main page, of can add a news or can logged himself out. &lt;/p&gt;

&lt;p&gt;On loading we applied navigation which will take the admin to home page if he is logged out and still trying to access this page. On logout() function we cleared the local storage and on the link Add News we navigated the admin to addnews.js. Location of this file is: &lt;em&gt;src&amp;gt;components&amp;gt;dashboard.js&lt;/em&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  Add News
&lt;/h2&gt;

&lt;p&gt;This component is accessible only for admin. He can post news over here. He can add title, description and body of the news. It will save the complete thread to object-type 'news' on the Cosmic JS server. Location of this component is: &lt;em&gt;src&amp;gt;components&amp;gt;addnews.js&lt;/em&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  Home Page
&lt;/h2&gt;

&lt;p&gt;On home page we are displaying all news which are published by the admin. First of all check its coding:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;This is the news.js and it is fetching as well as displaying the news on the home page of our app. We are explaining the working of getNews() method. If your device is online, then it is fetching data from backend and displaying on the template and also saving it on browser for offline use too. If the device is offline, then it will get the saved data from browser memory and will show to the user. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxpzi7g06t98wbls7si8k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxpzi7g06t98wbls7si8k.png" alt="Basic setting" width="800" height="647"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here you are seeing the title and description of the news and click to "Complete News" to read full story. This link will take you to next component:&lt;/p&gt;

&lt;h2&gt;
  
  
  Single News Component
&lt;/h2&gt;

&lt;p&gt;This component is fetching the single news which you clicked from the home page. Check its coding first:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;It is displaying the single news as well as there is an option of comment also. Comments related to the post are displayed here and you can add comments also. singleNews() method is fetching the news at one time and we applied a filter to get the selected news. allComments() function is getting all comments and filtering the comments related to this single post only.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fschcpsaeesd4ppzt9fne.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fschcpsaeesd4ppzt9fne.png" alt="Basic setting" width="800" height="691"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Services
&lt;/h2&gt;

&lt;p&gt;There are two services named authentication service and news service. Let us explain them one by one:&lt;/p&gt;

&lt;p&gt;Authentication Service: This is only for logging the admin in. There is one method defined which is searching the email and password supplied the the login page and returns the result to calling method. &lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;News Service: This is the main service of this project which is handling almost everything here. Go through its coding first:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Let's explain its methods one by one:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;addNews()&lt;/strong&gt;: It takes four parameters: title, description, newsbody and date and saves on the object type news&lt;br&gt;
&lt;strong&gt;getNews()&lt;/strong&gt;: As the name specifies, it fetch all news from the object-type news&lt;br&gt;
&lt;strong&gt;submitComment()&lt;/strong&gt;: This method submits the comment in the object type "comment"&lt;br&gt;
&lt;strong&gt;allComments()&lt;/strong&gt;: This get the submitted comments in object-type "comments" on the Cosmic JS server&lt;/p&gt;
&lt;h2&gt;
  
  
  Data Modelling
&lt;/h2&gt;

&lt;p&gt;We managed data on Cosmic JS properly, for this we created some object-types to understand the nature of each datum. Here is three object types : admin, news and comment. Admin stores the information of admin, and news stores the news published by admin. Comment object-type is storing the comments published by readers of our news app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq4aqyqxj9krc50acaa1k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq4aqyqxj9krc50acaa1k.png" alt="Basic setting" width="800" height="422"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What Have We Built Till Now?
&lt;/h2&gt;

&lt;p&gt;I want to make clear that our app is an ordinary app until now (in development mode); it doesn't have any PWA features, so let's start making it progressive in nature. When we created this app, it already created a file serviceWorker.js in the src folder, which handles the progressive nature of the app. At the time of online use, it automatically stores the static data of the app and reflects when the app is offline. &lt;/p&gt;

&lt;p&gt;Our app is not behaving a PWA because in serviceWorker it is coded to become a PWA only in production mode. So make its build and then run build, you will get some messages in the console like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6bbpfuvp0fz2t2pljhzi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6bbpfuvp0fz2t2pljhzi.png" alt="Basic setting" width="800" height="292"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the static data capturing of the app. If you want to capture the dynamic data, you need to code it manually. We did this in the news.js file. We stored the app data when the app is online and it automatically called when app will be offline. So to enjoy its PWA feature, run the following commands:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;npm run build&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;serve -s build&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Our app is partial-progressive in nature now. It is storing data while offline but it can't be installed on the device yet. We'll make that happen in the next step.&lt;/p&gt;
&lt;h2&gt;
  
  
  Make App Complete PWA
&lt;/h2&gt;

&lt;p&gt;To make it complete PWA, here is the final step. We need to edit manifest.json, which is present in the public folder. It should look like:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Here we added path of two icons, one for desktop and the other for mobile. Their size should be exactly the same and these two icons should be present in the public folder. Start_url is showing the path of build. This is the main basic coding of manifest and now our app is pure progressive in nature.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F33mfyjacqa8cjrl68ejw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F33mfyjacqa8cjrl68ejw.png" alt="PWA" width="800" height="462"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In ths above screenshot you can clearly check that Chrome browser is giving the option to install this React app on your system. &lt;/p&gt;

&lt;p&gt;Now we are checking out app with lighthouse tool, which is provided by Google to check PWAs, check output of lighthouse below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0hie48xmv4w5s49sbm3s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0hie48xmv4w5s49sbm3s.png" alt="Lighthouse" width="800" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In report each milestone achieved by our app except 7th, which is an https related and will be fixed as we deployed it to our Cosmic JS server which supports HTTPs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploy on Cosmic Server
&lt;/h2&gt;

&lt;p&gt;Now our app is ready and needs some improvement before deployment on Cosmic server. Make sure the followings:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A public GitHub repo ( private also available if you have connected your Git account )&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://devcenter.heroku.com/" rel="noopener noreferrer"&gt;Heroku requirements&lt;/a&gt; should be matched
You need to follow some steps:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;-&amp;gt; Install express with command: npm install --save express&lt;br&gt;
-&amp;gt; Modify your package.json file, and add the following code&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now create a file app.js in the root folder and add the following code in it&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Finally you made all necessary changes and it is now ready to deploy. Now go to: &lt;em&gt;bucket&amp;gt;setting&amp;gt;deployment&lt;/em&gt; and click button deploy to Cosmic. After successful deployment you will receive an email and click on "view app" button to view the app. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7tylgieof6drj2fk2kh5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7tylgieof6drj2fk2kh5.png" alt="Button" width="800" height="503"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Verdict
&lt;/h2&gt;

&lt;p&gt;It is clear that with the help of Cosmic JS we can create powerful apps and can deploy on their server without any server setting or configuration. Here we created and deployed our React.js progressive application on Cosmic server easily without any difficulty. You don't need to install any extra software to deploy over here. &lt;/p&gt;

&lt;p&gt;For any query or comment related to building apps in Cosmic JS, &lt;a href="https://twitter.com/cosmic_js" rel="noopener noreferrer"&gt;reach out to us on Twitter&lt;/a&gt; and &lt;a href="https://cosmicjs.com/community" rel="noopener noreferrer"&gt;join the conversation on Slack&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>react</category>
      <category>cosmicjs</category>
      <category>javascript</category>
      <category>pwa</category>
    </item>
  </channel>
</rss>
