<?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: Origho Precious</title>
    <description>The latest articles on DEV Community by Origho Precious (@orighoprecious).</description>
    <link>https://dev.to/orighoprecious</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%2F371057%2F74141f56-dd60-4a3b-b9d7-091d6d5f0382.JPG</url>
      <title>DEV Community: Origho Precious</title>
      <link>https://dev.to/orighoprecious</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/orighoprecious"/>
    <language>en</language>
    <item>
      <title>How to add live cursors to your product with Next.js and Liveblocks using the public key API.</title>
      <dc:creator>Origho Precious</dc:creator>
      <pubDate>Wed, 10 Nov 2021 09:08:03 +0000</pubDate>
      <link>https://dev.to/orighoprecious/how-to-add-live-cursors-to-your-product-with-nextjs-and-liveblocks-using-the-public-key-api-437n</link>
      <guid>https://dev.to/orighoprecious/how-to-add-live-cursors-to-your-product-with-nextjs-and-liveblocks-using-the-public-key-api-437n</guid>
      <description>&lt;p&gt;Almost everyone loves real-time collaborating tools especially developers. Take the Figma real-time indication of viewers' cursor for example. When on a Figma design board, you can see exactly where other viewers are. It’s awesome, right? I bet we all love it. This real-time feature/experience is exactly what  &lt;a href="https://liveblocks.io/" rel="noopener noreferrer"&gt;Liveblocks&lt;/a&gt;  provides. With Liveblocks, we don’t have to use WebSockets directly or use the popular  &lt;a href="https://socket.io/" rel="noopener noreferrer"&gt;socket.io&lt;/a&gt;. We can add real-time experience to our product using some of the Liveblocks integrations. Click  &lt;a href="https://liveblocks.io/blog/introducing-liveblocks" rel="noopener noreferrer"&gt;here&lt;/a&gt;  to read a more detailed overview of Liveblocks.&lt;/p&gt;

&lt;p&gt;In this article, we will learn how to add a live cursor to a Next.js app using Liveblocks public key API. To do this, we will clone a Next.js app (Windbnb - a mini Airbnb clone), integrate it with Liveblocks, and add a live cursor to it. &lt;/p&gt;

&lt;p&gt;Get started by cloning the Next.js app from Github. Open your terminal and run the command below.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/Origho-precious/windbnb-next.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You should have git installed on your computer for the above command to work. If you don’t have git installed already, you can do that from  &lt;a href="https://git-scm.com/downloads" rel="noopener noreferrer"&gt;here&lt;/a&gt;. After downloading and installing git, run the above command to clone the project.&lt;/p&gt;

&lt;p&gt;After cloning the repo, navigate into the project’s folder and run the command below to install the project’s dependencies. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;OR&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Open the project in your favorite code editor. The folder structure should look like this.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;📦public
 ┣ 📜favicon.ico
 ┗ 📜vercel.svg
📦src
 ┣ 📂components
 ┃ ┣ 📂Cursor
 ┃ ┃ ┗ 📜Cursor.jsx
 ┃ ┗ 📂Nav
 ┃ ┃ ┣ 📜Nav.jsx
 ┃ ┃ ┗ 📜nav.module.css
 ┣ 📂pages
 ┃ ┣ 📜_app.js
 ┃ ┗ 📜index.js
 ┣ 📂styles
 ┃ ┣ 📜Home.module.css
 ┃ ┗ 📜globals.css
 ┗ 📜data.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Let’s quickly go over the components and some of the files we have there. In the &lt;code&gt;src&lt;/code&gt; folder, we have three folders;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;components&lt;/code&gt;: this folder contains two components 

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Nav&lt;/code&gt;, the Nav component handles searching in the app, and &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Cursor&lt;/code&gt;, we will use this to indicate the presence of other users in the app with the help of Liveblocks.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;pages&lt;/code&gt;: since this is a Next.js app, the page handles the route, and there we have a file named index.js. This page renders some Airbnb locations in Finland. And also the Nav for searching.&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;styles&lt;/code&gt;: this houses the app’s CSS files.&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Integrating Liveblocks with Next.js.
&lt;/h2&gt;

&lt;p&gt;In this section, we will integrate our windbnb app with Liveblocks and add live cursors. To achieve this, we need to signup on  &lt;a href="https://liveblocks.io/" rel="noopener noreferrer"&gt;liveblocks.io&lt;/a&gt;  to get a public key with which we can successfully integrate our app with Liveblocks.&lt;/p&gt;

&lt;p&gt;Let’s head over to the Liveblocks website by clicking  &lt;a href="https://liveblocks.io/" rel="noopener noreferrer"&gt;here&lt;/a&gt;. On the navbar, you’ll see a “Sign up” link, click on it to signup. After signing up, you will be logged in automatically and routed to your dashboard. Your dashboard should look like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_27A83426A3E75CCE69E1720B438BEF4BF49491EC9C2F982941D361D35E04E4E3_1636053056856_Screenshot%2Bfrom%2B2021-11-04%2B20-10-29.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%2Fpaper-attachments.dropbox.com%2Fs_27A83426A3E75CCE69E1720B438BEF4BF49491EC9C2F982941D361D35E04E4E3_1636053056856_Screenshot%2Bfrom%2B2021-11-04%2B20-10-29.png" alt="Liveblocks dashboard"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Check your email for a verification mail from Liveblocks to activate your account. In your dashboard,&lt;br&gt;
click on “API Keys” on the sidebar and copy your public key. For security reasons, you might want to create a .env file and save the public key there so it’s not accessible to everyone. &lt;/p&gt;

&lt;p&gt;For the integration, we will need two packages provided by Liveblocks;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://liveblocks.io/docs/api-reference/liveblocks-client" rel="noopener noreferrer"&gt;&lt;code&gt;@liveblocks/client&lt;/code&gt;&lt;/a&gt;: This package lets you create a client to connect to Liveblocks servers.&lt;/li&gt;
&lt;li&gt; &lt;a href="https://liveblocks.io/docs/api-reference/liveblocks-react" rel="noopener noreferrer"&gt;&lt;code&gt;@liveblocks/react&lt;/code&gt;&lt;/a&gt;: This package provides hooks to make it easier to use the Liveblocks client in a React app.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We will get a better understanding when we use them in the next section. In your terminal, run the command below to install them.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add @liveblocks/client @liveblocks/react
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;OR&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install @liveblocks/client @liveblocks/react
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;N.B: This article assumes you have a basic understanding of React and Nextjs, so it focuses on explaining Liveblocks integration and not React and Nextjs specific syntax. &lt;/p&gt;

&lt;p&gt;In your code editor, navigate to &lt;code&gt;src/pages/_app.js&lt;/code&gt;. We will add Liveblocks integration in there by updating the content of the file with the code below.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { createClient } from "@liveblocks/client";
import { LiveblocksProvider } from "@liveblocks/react";
import "../styles/globals.css";

const client = createClient({
  publicApiKey: {YOUR PUBLIC KEY}, 
});

function MyApp({ Component, pageProps }) {
  return (
    &amp;lt;LiveblocksProvider client={client}&amp;gt;
      &amp;lt;Component {...pageProps} /&amp;gt;
    &amp;lt;/LiveblocksProvider&amp;gt;
  );
}
export default MyApp;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;We’ve successfully configured our app to use Liveblocks. We imported; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; &lt;a href="https://liveblocks.io/docs/api-reference/liveblocks-client#createClient" rel="noopener noreferrer"&gt;createClient&lt;/a&gt;; This function creates a client using a public key. With this client we can communicate with Liveblocks servers.&lt;/li&gt;
&lt;li&gt; &lt;a href="https://liveblocks.io/docs/api-reference/liveblocks-react#LiveblocksProvider" rel="noopener noreferrer"&gt;LiveblocksProvider&lt;/a&gt;. This is a context provider for the state of the client we created with &lt;code&gt;createClient&lt;/code&gt; as in  &lt;a href="https://reactjs.org/docs/context.html" rel="noopener noreferrer"&gt;React Context API&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We then passed the client we created with our public key to &lt;code&gt;LiveblocksProvider&lt;/code&gt; and wrapped the entire app with it, thereby making data from the server available to be consumed by any component in the app. &lt;/p&gt;

&lt;p&gt;Next, we will create a Room that any user viewing the page will be connected to. To achieve this, we need to create a Component to show the presence of users on the page including our presence. Navigate to &lt;code&gt;src/components&lt;/code&gt; in here, create a folder called &lt;code&gt;Presence&lt;/code&gt; and a file inside it called &lt;code&gt;Presence.jsx&lt;/code&gt;. Add the code below to the file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useMyPresence, useOthers } from "@liveblocks/react";
    import Cursor from "../Cursor/Cursor";
    const COLORS = [
      "#E57373",
      "#9575CD",
      "#4FC3F7",
      "#81C784",
      "#FFF176",
      "#FF8A65",
      "#F06292",
      "#7986CB",
    ];

    const Presence = () =&amp;gt; {
      const [{ cursor }, updateMyPresence] = useMyPresence();
      const others = useOthers();

      return (
        &amp;lt;div
          style={{
            position: "fixed",
            height: "100vh",
            left: 0,
            top: 0,
            width: "100vw",
            zIndex: 5,
          }}
          onPointerMove={(event) =&amp;gt;
            updateMyPresence({
              cursor: {
                x: Math.round(event.clientX),
                y: Math.round(event.clientY),
              },
            })
          }
          onPointerLeave={() =&amp;gt;
            updateMyPresence({
              cursor: null,
            })
          }
        &amp;gt;
          &amp;lt;div
            style={{
              textAlign: "left",
              color: "#81C784",
              transform: `translateX(${cursor?.x || 0}px) translateY(${
                cursor?.y || 0
              }px)`,
            }}
          &amp;gt;
            {cursor ? `ME` : ""}
          &amp;lt;/div&amp;gt;
          {others.map(({ connectionId, presence }) =&amp;gt; {
            if (presence == null || presence.cursor == null) {
              return null;
            }
            return (
              &amp;lt;Cursor
                key={`cursor-${connectionId}`}
                color={COLORS[connectionId % COLORS.length]}
                x={presence.cursor.x}
                y={presence.cursor.y}
              /&amp;gt;
            );
          })}
        &amp;lt;/div&amp;gt;
      );
    };

    export default Presence;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Above, We imported  &lt;a href="https://liveblocks.io/docs/api-reference/liveblocks-react#useMyPresence" rel="noopener noreferrer"&gt;&lt;code&gt;useMyPresence&lt;/code&gt;&lt;/a&gt;, and  &lt;a href="https://liveblocks.io/docs/api-reference/liveblocks-react#useOthers" rel="noopener noreferrer"&gt;&lt;code&gt;useOthers&lt;/code&gt;&lt;/a&gt;  from &lt;code&gt;@liveblocks/react&lt;/code&gt;. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;useMyPresence&lt;/code&gt; is a hook. It contains the current position of the current user (that is, you viewing the page) and a function to update it.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;useOthers&lt;/code&gt; is also a hook. It returns every other user connected to the room. but unlike &lt;code&gt;useMyPresence&lt;/code&gt;, it doesn’t have a setter function. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I know the concept of a room might sound strange. When using Liveblocks, you have to create a room and each room should have a unique Id. This is done using a component provided by Liveblocks;  &lt;a href="https://liveblocks.io/docs/api-reference/liveblocks-react#RoomProvider" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;code&gt;RoomProvider&lt;/code&gt;&lt;/strong&gt;&lt;/a&gt;. Only components wrapped by the &lt;code&gt;RoomProvider&lt;/code&gt; will be able to access the data from other users in the room. &lt;/p&gt;

&lt;p&gt;After that, we created an array of HEX colors, we will dynamically assign these colors to the cursor of other users on that page. Using the data from &lt;code&gt;useMyPresence&lt;/code&gt; and &lt;code&gt;useOthers&lt;/code&gt;, we rendered some &lt;code&gt;jsx&lt;/code&gt; to show the position of the current user and of others on the page.&lt;/p&gt;

&lt;p&gt;Now let’s create a room and wrap the page with it by navigating to &lt;code&gt;src/pages/index.js&lt;/code&gt; and updating the code there to be the one below.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useEffect, useState } from "react";
import Head from "next/head";
import { RoomProvider } from "@liveblocks/react";
import styles from "../styles/Home.module.css";
import SearchNav from "../components/Nav/Nav";
import data from "../data";
import Presence from "../components/Presence/Presence";

const Home = () =&amp;gt; {
  const [search, setSearch] = useState("");
  const [results, setResults] = useState(data);
  const [stays, setStays] = useState(data.length);
  useEffect(() =&amp;gt; {
    const processSearchResult = () =&amp;gt; {
      if (search) {
        const filteredResult = data.filter((item) =&amp;gt; {
          return (
            `${item.city}, ${item.country}` === search.location &amp;amp;&amp;amp;
            item.maxGuests &amp;gt; search.guests
          );
        });
        setResults(filteredResult);
        setStays(filteredResult.length);
      }
    };
    processSearchResult();
  }, [search]);

  const renderHouses = () =&amp;gt; {
    return results.map((item) =&amp;gt; {
      return (
        &amp;lt;div className={styles.gridItem} key={item.title}&amp;gt;
          &amp;lt;img src={item.photo} alt={item.title} /&amp;gt;
          &amp;lt;div className={styles.texts}&amp;gt;
            {item.superHost ? (
              &amp;lt;span className={styles.superHost}&amp;gt;SUPERHOST&amp;lt;/span&amp;gt;
            ) : null}
            &amp;lt;span&amp;gt;
              {item.type} &amp;amp;nbsp; {item.beds ? `${item.beds} beds` : null}
            &amp;lt;/span&amp;gt;
            &amp;lt;span&amp;gt;
              &amp;lt;i className="fas fa-star"&amp;gt;&amp;lt;/i&amp;gt; {item.rating}
            &amp;lt;/span&amp;gt;
          &amp;lt;/div&amp;gt;
          &amp;lt;p&amp;gt;{item.title}&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
      );
    });
  };

  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;Head&amp;gt;
        &amp;lt;meta name="theme-color" content="#EF7B7B" /&amp;gt;
        &amp;lt;meta
          name="description"
          content="Windbnb: Airbnb clone for stays in Finland"
        /&amp;gt;
        &amp;lt;link rel="icon" href="/favicon.ico" /&amp;gt;
        &amp;lt;link
          rel="stylesheet"
          href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta2/css/all.min.css"
          integrity="sha512-YWzhKL2whUzgiheMoBFwW8CKV4qpHQAEuvilg9FAn5VJUDwKZZxkJNuGM4XkWuk94WCrrwslk8yWNGmY1EduTA=="
          crossOrigin="anonymous"
          referrerpolicy="no-referrer"
        /&amp;gt;
        &amp;lt;title&amp;gt;Windbnb - Airbnb Clone&amp;lt;/title&amp;gt;
      &amp;lt;/Head&amp;gt;
      &amp;lt;RoomProvider
        id="windbnb"
        defaultPresence={() =&amp;gt; ({
          cursor: null,
        })}
      &amp;gt;
        &amp;lt;Presence /&amp;gt;
        &amp;lt;SearchNav getSearch={setSearch} /&amp;gt;
        &amp;lt;main className={styles.Home}&amp;gt;
          &amp;lt;header&amp;gt;
            &amp;lt;h2&amp;gt;Stays in Finland&amp;lt;/h2&amp;gt;
            &amp;lt;p&amp;gt;{stays ? `${stays} stay(s)` : "12+ stays"}&amp;lt;/p&amp;gt;
          &amp;lt;/header&amp;gt;
          &amp;lt;div className={styles.grid}&amp;gt;{renderHouses()}&amp;lt;/div&amp;gt;
        &amp;lt;/main&amp;gt;
      &amp;lt;/RoomProvider&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default Home;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We have now completely added live cursor to our Next.js app using Liveblocks. You can go ahead and test the app by starting the dev server with the command below.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;OR&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Go to your browser and visit &lt;a href="http://localhost:3000" rel="noopener noreferrer"&gt;http://localhost:3000&lt;/a&gt;. If you followed along very well, you should see a page like the one below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_27A83426A3E75CCE69E1720B438BEF4BF49491EC9C2F982941D361D35E04E4E3_1636064795527_Screenshot%2Bfrom%2B2021-11-04%2B23-22-45.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%2Fpaper-attachments.dropbox.com%2Fs_27A83426A3E75CCE69E1720B438BEF4BF49491EC9C2F982941D361D35E04E4E3_1636064795527_Screenshot%2Bfrom%2B2021-11-04%2B23-22-45.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you see any errors in your console or browser, please re-read the article from the beginning and compare your code with the final version (link in the next section).&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources for more learning.
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt; &lt;a href="https://liveblocks.io/blog/introducing-liveblocks" rel="noopener noreferrer"&gt;Introduction to Liveblocks.&lt;/a&gt; &lt;/li&gt;
&lt;li&gt; &lt;a href="https://liveblocks.io/docs" rel="noopener noreferrer"&gt;Liveblocks official documentation.&lt;/a&gt; &lt;/li&gt;
&lt;li&gt; &lt;a href="https://liveblocks.io/docs/guides/get-started/react" rel="noopener noreferrer"&gt;Getting started with Liveblocks and React.&lt;/a&gt; &lt;/li&gt;
&lt;li&gt; &lt;a href="https://github.com/Origho-precious/windbnb-next/tree/main" rel="noopener noreferrer"&gt;Article project repository starting code.&lt;/a&gt; &lt;/li&gt;
&lt;li&gt; &lt;a href="https://github.com/Origho-precious/windbnb-next/tree/completed" rel="noopener noreferrer"&gt;Final version of Article Project Code&lt;/a&gt; &lt;/li&gt;
&lt;li&gt; &lt;a href="https://github.com/liveblocks/liveblocks/tree/main/examples/nextjs-live-cursors" rel="noopener noreferrer"&gt;Liveblocks official example of live cursor.&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>nextjs</category>
      <category>liveblocks</category>
      <category>websocket</category>
      <category>realtime</category>
    </item>
    <item>
      <title>Saving Netlify App Secrets using Doppler</title>
      <dc:creator>Origho Precious</dc:creator>
      <pubDate>Fri, 01 Oct 2021 19:23:25 +0000</pubDate>
      <link>https://dev.to/orighoprecious/saving-netlify-app-secrets-using-doppler-3a4n</link>
      <guid>https://dev.to/orighoprecious/saving-netlify-app-secrets-using-doppler-3a4n</guid>
      <description>&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;When deploying applications on &lt;a href="https://www.netlify.com/"&gt;netlify&lt;/a&gt;, we usually add our app’s environment variables manually. And whenever there’s a need to update it, we have to go back there to netlify to do it. With &lt;a href="https://www.doppler.com/"&gt;Doppler&lt;/a&gt;, an organization/team or individuals can manage their application’s environment variables easily. In this article, we will be learning how to integrate Doppler with Netlify.&lt;/p&gt;

&lt;h2&gt;
  
  
  Goal
&lt;/h2&gt;

&lt;p&gt;In this article, we will clone a mini e-commerce project built with Reactjs that uses firebase for authentication from Github, save the app’s environment variables in a doppler workspace and sync it with netlify. To achieve this, we will set up a doppler account, create a workspace, add a project to the workspace and sync it with netlify. At the end of this article, readers will know how to integrate Doppler with netlify.&lt;/p&gt;

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

&lt;p&gt;You should have a netlify account. If you don’t already, you can create one &lt;a href="https://app.netlify.com/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Doppler and why should I use it?
&lt;/h2&gt;

&lt;p&gt;Following the first two sections of this article, you might be wondering, “what exactly is doppler?”. In this section, we will briefly go over what doppler is and why you should use it.&lt;/p&gt;

&lt;p&gt;Doppler is a universal secret manager. It helps Software Engineers store/manage credentials used in their applications just like the traditional .env files. With doppler, we can share secret credentials/variables across many platforms, in several programming languages. See all the possible doppler integrations &lt;a href="https://www.doppler.com/integrations"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;With Doppler, we can manage all the secret credentials/variables used in an application across different platforms in one place (a single source of truth), for example, if your company has a MERN stack app with the frontend deployed on netlify, and maybe a test version of the frontend on vercel and the backend on AWS, you can easily manage all the credentials used in all these platforms with doppler. It's that easy and fast.&lt;/p&gt;

&lt;h2&gt;
  
  
  Syncing Doppler with Netlify
&lt;/h2&gt;

&lt;p&gt;In this section, we will learn how to sync credentials saved in doppler with an app deployed on netlify. To get started, Let’s clone the project we will be deploying on netlify from Github using the code below. To do this, you need to have git installed in your machine.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/Origho-precious/ecommerce-project.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Next, create a repository and add the project to it. You need to do this to deploy the project on netlify via Github. After doing that, log in to your netlify account and deploy the application there.&lt;/p&gt;

&lt;p&gt;The next thing to do is to set up a doppler workspace, create a project for the e-commerce app, and add the env variables we need in the app. let’s do that below.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a Doppler Workspace.
&lt;/h2&gt;

&lt;p&gt;When creating a doppler account, you will be prompted to create a workspace. You can add your team members to it and manage the access level each person should have in that workspace.&lt;/p&gt;

&lt;p&gt;Let’s create a doppler workspace. Let’s get started by visiting the doppler official &lt;a href="https://www.doppler.com/"&gt;website&lt;/a&gt; and creating an account.  After that, we will get to a screen where we need to create a workspace as seen below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TZ4vkJXY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_C8A574BD921C55D698018569E18F79A0CE43B6242CA7E8E147D97020B3D23ECB_1632858697769_s_58727F8984E67F39A261CDB28758B66C8658E243E7EA77385CC78B8C67BB1481_1631114800389_createworkspace.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TZ4vkJXY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_C8A574BD921C55D698018569E18F79A0CE43B6242CA7E8E147D97020B3D23ECB_1632858697769_s_58727F8984E67F39A261CDB28758B66C8658E243E7EA77385CC78B8C67BB1481_1631114800389_createworkspace.png" alt="create workspace screen"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After filling and submitting the form. the workspace will be created, and we will be routed to a screen like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--l9znzknT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_C8A574BD921C55D698018569E18F79A0CE43B6242CA7E8E147D97020B3D23ECB_1632859330094_Screenshot%2Bfrom%2B2021-09-28%2B09-17-09.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--l9znzknT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_C8A574BD921C55D698018569E18F79A0CE43B6242CA7E8E147D97020B3D23ECB_1632859330094_Screenshot%2Bfrom%2B2021-09-28%2B09-17-09.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That is what your workspace should be like if you create a new workspace. If you notice, there’s a test project added there already, but we won’t be using that. Let’s add a new project for the e-commerce app by clicking on the plus icon there.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--udBTmOoi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_C8A574BD921C55D698018569E18F79A0CE43B6242CA7E8E147D97020B3D23ECB_1632861208771_Screenshot%2Bfrom%2B2021-09-28%2B10-08-41.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--udBTmOoi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_C8A574BD921C55D698018569E18F79A0CE43B6242CA7E8E147D97020B3D23ECB_1632861208771_Screenshot%2Bfrom%2B2021-09-28%2B10-08-41.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As seen above, I named my project &lt;code&gt;firebase-commerce&lt;/code&gt; and added a description. Next, we need to add the environment variables needed in the project. Clicking on the project we just created will take us to a screen like the one below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WSZ4jlfs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_C8A574BD921C55D698018569E18F79A0CE43B6242CA7E8E147D97020B3D23ECB_1632861390113_Screenshot%2Bfrom%2B2021-09-28%2B20-57-43.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WSZ4jlfs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_C8A574BD921C55D698018569E18F79A0CE43B6242CA7E8E147D97020B3D23ECB_1632861390113_Screenshot%2Bfrom%2B2021-09-28%2B20-57-43.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There you’ll see different environments prepopulated for us, development, staging, and production. We can add different variables needed in each environment. And if they all use the same variables, we can easily add them to one and sync them across all environments. Note that we can also add custom environments by clicking on the hamburger icon at the top right of the page.&lt;/p&gt;

&lt;p&gt;Let’s add variables to the development environment, and also sync them to the two others. To do this, we need to click on the rectangle with dev in it. It will open a page like the one below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Y56TtagO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_C8A574BD921C55D698018569E18F79A0CE43B6242CA7E8E147D97020B3D23ECB_1632861976587_screencapture-dashboard-doppler-workplace-a31b2e7f4aa371ae185d-projects-firebase-commerce-configs-dev-2021-09-28-21_00_19.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y56TtagO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_C8A574BD921C55D698018569E18F79A0CE43B6242CA7E8E147D97020B3D23ECB_1632861976587_screencapture-dashboard-doppler-workplace-a31b2e7f4aa371ae185d-projects-firebase-commerce-configs-dev-2021-09-28-21_00_19.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can add variables singly by clicking on the ‘Add first Secret' or by clicking on the other button and where we import all our variables from  &lt;code&gt;ENV&lt;/code&gt;, &lt;code&gt;JSON&lt;/code&gt;, or &lt;code&gt;YAML&lt;/code&gt; format. We will use the second option to make things faster. Click on the button. You should see a screen like the one below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EqN-er_u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_C8A574BD921C55D698018569E18F79A0CE43B6242CA7E8E147D97020B3D23ECB_1632862304599_Screenshot%2Bfrom%2B2021-09-28%2B21-00-46.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EqN-er_u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_C8A574BD921C55D698018569E18F79A0CE43B6242CA7E8E147D97020B3D23ECB_1632862304599_Screenshot%2Bfrom%2B2021-09-28%2B21-00-46.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy and paste the below code into the textarea provided and click on ‘Import Secrets` below.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;REACT_APP_APIKEY = AIzaSyBzklmuZsb_5Ait1FatkT-Mg3Vor1hFJ8A
REACT_APP_AUTH_DOMAIN = ecomerce-project-40990.firebaseapp.com
REACT_APP_DATABASE_URL = https://ecomerce-project-40990.firebaseio.com
REACT_APP_PROJECT_ID = ecomerce-project-40990
REACT_APP_STORAGE_BUCKET = ecomerce-project-40990.appspot.com
REACT_APP_SENDER_ID = 361284578530
REACT_APP_APP_ID = 1=361284578530:web:58896ab84048601b9682bb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Importing it will take us back to this screen with all the variables set up.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--v9HY9e6Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_C8A574BD921C55D698018569E18F79A0CE43B6242CA7E8E147D97020B3D23ECB_1632862459544_screencapture-dashboard-doppler-workplace-a31b2e7f4aa371ae185d-projects-firebase-commerce-configs-dev-2021-09-28-21_53_21.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--v9HY9e6Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_C8A574BD921C55D698018569E18F79A0CE43B6242CA7E8E147D97020B3D23ECB_1632862459544_screencapture-dashboard-doppler-workplace-a31b2e7f4aa371ae185d-projects-firebase-commerce-configs-dev-2021-09-28-21_53_21.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There’s a ‘Save’ button at the top right of the page, click on it to save the variables.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--q8z-Yzh_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_C8A574BD921C55D698018569E18F79A0CE43B6242CA7E8E147D97020B3D23ECB_1632862725709_Screenshot%2Bfrom%2B2021-09-28%2B21-58-30.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--q8z-Yzh_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_C8A574BD921C55D698018569E18F79A0CE43B6242CA7E8E147D97020B3D23ECB_1632862725709_Screenshot%2Bfrom%2B2021-09-28%2B21-58-30.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I’m selecting the two other environments do they will have the environment variables also. &lt;/p&gt;

&lt;p&gt;We have now set up a doppler account, a workspace, and a project. We also variables to environments in the project. Next, let’s add a netlify integration to this project. to do this click on ‘Integrations’.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uVsz_aST--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_C8A574BD921C55D698018569E18F79A0CE43B6242CA7E8E147D97020B3D23ECB_1632863046640_Screenshot%2Bfrom%2B2021-09-28%2B22-03-21.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uVsz_aST--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_C8A574BD921C55D698018569E18F79A0CE43B6242CA7E8E147D97020B3D23ECB_1632863046640_Screenshot%2Bfrom%2B2021-09-28%2B22-03-21.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, let’s add a netlify integration by clicking on the ‘Add Integration’ button. then select netlify&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SSoCj2Qf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_C8A574BD921C55D698018569E18F79A0CE43B6242CA7E8E147D97020B3D23ECB_1632863277735_Screenshot%2Bfrom%2B2021-09-28%2B22-07-38.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SSoCj2Qf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_C8A574BD921C55D698018569E18F79A0CE43B6242CA7E8E147D97020B3D23ECB_1632863277735_Screenshot%2Bfrom%2B2021-09-28%2B22-07-38.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We will be routed to a page where we need to authorize netlify to use doppler&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hMjk6xw5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_C8A574BD921C55D698018569E18F79A0CE43B6242CA7E8E147D97020B3D23ECB_1632863463701_Screenshot%2Bfrom%2B2021-09-28%2B10-25-27.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hMjk6xw5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_C8A574BD921C55D698018569E18F79A0CE43B6242CA7E8E147D97020B3D23ECB_1632863463701_Screenshot%2Bfrom%2B2021-09-28%2B10-25-27.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we select the website needed from the list of sites we have deployed to netlify. At this point, If you are yet to deploy the e-commerce project to netlify, you need to do it now to continue.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JpetiJQT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_C8A574BD921C55D698018569E18F79A0CE43B6242CA7E8E147D97020B3D23ECB_1632863747128_Screenshot%2Bfrom%2B2021-09-28%2B22-15-07.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JpetiJQT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_C8A574BD921C55D698018569E18F79A0CE43B6242CA7E8E147D97020B3D23ECB_1632863747128_Screenshot%2Bfrom%2B2021-09-28%2B22-15-07.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As seen above, we will also select the config we want to use from the environments we have in the project e.g &lt;code&gt;development&lt;/code&gt;, &lt;code&gt;staging&lt;/code&gt; and &lt;code&gt;production&lt;/code&gt;. I will go with &lt;code&gt;development (dev)&lt;/code&gt;. The last input is for selecting which variables should be used in cases where we have variables from doppler and netlify. I set my preference to doppler. When you’re done, click on the button below.&lt;/p&gt;

&lt;p&gt;We have now integrated the project we deployed on netlify with our secrets from doppler.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_5t3isDC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_C8A574BD921C55D698018569E18F79A0CE43B6242CA7E8E147D97020B3D23ECB_1632864273048_Screenshot%2Bfrom%2B2021-09-28%2B22-23-29.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_5t3isDC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_C8A574BD921C55D698018569E18F79A0CE43B6242CA7E8E147D97020B3D23ECB_1632864273048_Screenshot%2Bfrom%2B2021-09-28%2B22-23-29.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To verify that the variables on the doppler workspace are correctly integrated with the netlify app, go to the project on netlify and check the environment variables. You can see mine below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wAwBQ395--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_C8A574BD921C55D698018569E18F79A0CE43B6242CA7E8E147D97020B3D23ECB_1632864550128_Screenshot%2Bfrom%2B2021-09-28%2B22-28-52.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wAwBQ395--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_C8A574BD921C55D698018569E18F79A0CE43B6242CA7E8E147D97020B3D23ECB_1632864550128_Screenshot%2Bfrom%2B2021-09-28%2B22-28-52.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can go ahead and test the app if you want using the netlify site link.&lt;/p&gt;

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

&lt;p&gt;We have now learned how to save secrets in doppler and integrate them with Netlify. While learning to do this, we learned how to create a doppler workspace and how to add environment variables/secrets. We did this and were also able to confirm they were added correctly to the project on netlify. Now you see how easy and fast is it to manage netlify app secrets with doppler, you will see more of the advantages when you want to update any of the variables. We can do that in the doppler workspace and save it, any platform integrated with that workspace will be updated accordingly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources for More Learning
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://dev.to/umavictor6/intro-to-doppler-real-life-use-case-4g1a"&gt;Intro to Doppler&lt;/a&gt;&lt;br&gt;
&lt;a href="https://docs.doppler.com/docs/netlify"&gt;Doppler Integration with Netlify Documentation&lt;/a&gt;&lt;/p&gt;

</description>
      <category>doppler</category>
      <category>security</category>
      <category>netlify</category>
      <category>env</category>
    </item>
    <item>
      <title>Object-Oriented Programming in Javascript(ES5 &amp; ES6) EXPLAINED.</title>
      <dc:creator>Origho Precious</dc:creator>
      <pubDate>Tue, 28 Apr 2020 12:59:43 +0000</pubDate>
      <link>https://dev.to/orighoprecious/object-oriented-programming-in-javascript-es5-es6-explained-4jbk</link>
      <guid>https://dev.to/orighoprecious/object-oriented-programming-in-javascript-es5-es6-explained-4jbk</guid>
      <description>&lt;h1&gt;
  
  
  INTRODUCTION
&lt;/h1&gt;

&lt;p&gt;OOP - Object-oriented Programming, in general, is very useful. It helps developers to model real-world things that we want to represent inside our code, and/or provide a simple way to access functionality that would otherwise be hard or impossible to make use of.&lt;br&gt;
Getting a full understanding of how OOP works in javascript is a bit difficult especially in ES5 syntax, ES6 class made it a lot easier to use object constructor but as developers, we will run into ES5 object prototype codes along our journey and in case you do not know, ES6 class, work as object prototypes under the hood.&lt;/p&gt;

&lt;p&gt;This article will explain javascript object in ES5 and ES6 syntax. Stay tuned!&lt;/p&gt;
&lt;h3&gt;
  
  
  WHY USE OBJECT CONSTRUCTOR NOTATION?
&lt;/h3&gt;

&lt;p&gt;You must have questioned the need for using object constructor and not stick with object literals. Well, object literals are easy and straight forward to understand but let's think of a scenario whereby we want to create an object from data gotten from an input field, for example; we have a website and in our website a form field that requests for the name, email, phone number, and address of our users. We want to use the data gotten from the form field to create an object as a way to keep user data together and then create a profile for each user and make sure each user should have the same properties(in this case name, email, number, and address). Using object literal notation requires us to create an object every time for each user, for instance from our form we got these data from three (3) users:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 1st user
const user1 = {                               
  name: 'Precious',
  email: 'precious@gmail.com',      
  number: '+234-810-5025-740',
  address: 'Earth'
}

// 2nd User
const user2 = {                               
  name: 'Frank',
  email: 'frank@gmail.com',      
  number: '+234-800-5525-540',
  address: 'Jupiter'
}

// 3rd User
const user3 = {                               
  name: 'Charles',
  email: 'charles@yahoo.com',      
  number: '+234-810-4985-376',
  address: 'Mars'
}

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

&lt;/div&gt;



&lt;p&gt;The code is repetitive and that is against the DRY(Don't Repeat Yourself) principle of programming and we don't want that. The perfect solution to that is using object constructor notation, and then making &lt;strong&gt;instances&lt;/strong&gt; of the object. Now let's write the above code using object constructor notation and how to make instances of an object:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Object Constructor(ES5)
function User(name, email, number, address){
  this.name = name;
  this.email = email;
  this.number= number;
  this.address = address;
}

// Instances
// 1st user
const user1 = new User('Precious', 'precious@gmail.com', '+234-810-5025-740', 'Earth');

// 2nd user
const user2 = new User('Frank', 'frank@gmail.com', '+234-800-5525-540', 'Jupiter');

// 3rd User
const user3 = new User('Charles', 'charles@yahoo.com', '+234-810-4985-376', 'Mars');

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

&lt;/div&gt;



&lt;p&gt;From the above code, we just created, we used a &lt;strong&gt;constructor&lt;/strong&gt; function which as the name implies is a function that constructs object &lt;strong&gt;instances&lt;/strong&gt; to create objects from the data each user submitted in the form. It is DRY and clean with the constructor notation, and values from the object can be accessed with the same syntax&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// OBJECT LITERAL NOTATION
// To get the name of the first user.
   console.log(user1.name) // Precious

// OBJECT CONSTRUCTOR NOTATION(ES5)
// To get the name of the first user.
   console.log(user1.name) // Precious
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let us explain some keywords that are used in the constructor notation.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The &lt;strong&gt;this&lt;/strong&gt; keyword: In case you do not know before now, The &lt;strong&gt;this&lt;/strong&gt; keyword in the constructor function above refers to the object itself i.e the user, meaning by saying &lt;strong&gt;this.name = name&lt;/strong&gt; we mean the name property of that user should be set to the value of the parameter &lt;strong&gt;name&lt;/strong&gt;. the &lt;strong&gt;this&lt;/strong&gt; actually means different things in different context but inside the object constructor it is as stated above&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;strong&gt;new&lt;/strong&gt; keyword is simply used to instantiate(create) a new object from the constructor.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  OBJECT CONSTRUCTOR IN ES5 AND ES6
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;h4&gt;ES5 Syntax&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Prototype and prototypal Inheritance:
We have looked at how object constructor is written in ES5 syntax now let's look at what an object prototype is. 
Syntax:
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Dog(name, age){
 // Properties
  this.name = name;
  this.age = age;

 // Method
  this.canBark = function(){
    if(this.age =&amp;gt; '180 days'){
       return 'YES';
    } else{
      return 'NO';
    }
  }
}

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

&lt;/div&gt;



&lt;p&gt;The method in the constructor function can better be written in javascript by writing it as a prototype like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Dog(name, age){
 // Properties
  this.name = name;
  this.age = age;
}

// Object Prototype
  Dog.prototype.canBark = function(){
    if(this.age =&amp;gt; '180 days'){
       return 'YES';
    } else{
      return 'NO';
    }
  }

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

&lt;/div&gt;



&lt;p&gt;Now, What is an Object Prototype? An object prototype is an object that is associated with every instance of an object by default in JavaScript. Prototypes allow you to easily define methods to all instances of a particular object. This is very useful in that the method is applied to the prototype, so it is only stored in the memory once, but every instance of the object has access to it.&lt;br&gt;
We can also add a property to the object using a prototype which is not possible normally after declaring a constructor function, but it should only be used for properties we want all instances to share:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Dog.prototype.breed = 'German shepherd'

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

&lt;/div&gt;



&lt;p&gt;What if we have another object that we want to have all the properties and methods of the first object and their own special properties and/or methods, what do we do keeping DRY in mind?&lt;br&gt;
The answer to that is provided by &lt;strong&gt;prototypes&lt;/strong&gt; &lt;strong&gt;inheritance&lt;/strong&gt; which simply means one object inheriting properties and methods of another. for instance, we want another group of dog to inherit some properties of the first group plus their own special properties(dog weight):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Group 1
function Group1(dogName, dogAge){
 // Properties
  this.dogName = dogName;
  this.dogAge = dogAge;
}

// Object Prototype
  Group1.prototype.canBark = function(){
    if(this.dogAge =&amp;gt; '180 days'){
       return 'YES';
    } else{
      return 'NO';
    }
  }

// Group 2
function Group2(dogName, dogAge, dogWeight){
  Group1.call(this, dogName, dogAge);
  this.dogWeight = dogWeight;
}

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

&lt;/div&gt;



&lt;p&gt;To Inherit the properties from the first group we used the call() method which is used to call the contractor we want to inherit its properties, and it takes in &lt;strong&gt;this&lt;/strong&gt; as the first parameter and then the parameters to be inherited from that constructor(in this case:- dogName and dogAge). After which we then set the special property of the object(in this case: dogWeight);&lt;br&gt;
This only inherits the properties and not the prototypes. To inherit the prototypes, we will say:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Group2.prototype = object.create(Group1.prototype);

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

&lt;/div&gt;



&lt;p&gt;With this, we have made the 2nd group of dogs possess all the properties and objects of the 1st group.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;h4&gt;ES6 Syntax&lt;/h4&gt;
Classes in ES6 is same as Object constructor function in ES5 under the hood that means both work in the same way just that ES6 has a much better syntax which one of my favorite tutor(Brad Traversy) calls "syntactic sugar" and also methods are directly made prototypes(made accessible to all instances of the Class). 
Now let's dive in ES6 classes.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Declaring an ES6 class &amp;amp; Constructor:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Person{
  constructor(firstName, lastName, age){
    this.firstName = firstName;
    this.lastName = lastName;    // PROPERTIES
    this.age = age;
  }

   getAge(){
     return `${this.firstName} ${this.lastName};   // METHOD
   }   
}

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

&lt;/div&gt;



&lt;p&gt;KEYWORDS EXPLANATION:&lt;br&gt;
A. &lt;strong&gt;class&lt;/strong&gt; - is simply used to declare a class(ES6 object) it is followed by the name of the object.&lt;br&gt;
B. &lt;strong&gt;constructor&lt;/strong&gt; - Just as we used function in ES5 syntax. constructor is used construct the object.&lt;/p&gt;

&lt;p&gt;NOTE: Value of objects in ES^ can be accessed in same way asin ES5 and also instantiation has the same syntax.&lt;/p&gt;

&lt;p&gt;As simple as that looks we have just written our first object using ES6 class.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Inheritance:
Inheritance in ES6 class has a different syntax and in involves using 2 new keyword &lt;strong&gt;extends&lt;/strong&gt; and &lt;strong&gt;Super&lt;/strong&gt;, let's take a look at it. if we want a customer object to inherit from the person object:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Person{
  constructor(firstName, lastName, age){
    this.firstName = firstName;
    this.lastName = lastName;    
    this.age = age;
  }

   getAge(){
     return `${this.firstName} ${this.lastName};   
   }   
}

class Customer extends Person{
  constructor(firstName, lastName, age, memberShip){
    Super(firstName, lastName, age)   
    this.memberShip = memberShip;
  } 
}

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

&lt;/div&gt;


&lt;p&gt;KEYWORDS EXPLANATION:&lt;br&gt;
A. &lt;strong&gt;extends&lt;/strong&gt; : specifies that the Customer object inherit the properties and methods the Person object.&lt;br&gt;
B. &lt;strong&gt;super&lt;/strong&gt; : Just asin call() in ES5 objects, &lt;strong&gt;super&lt;/strong&gt; states the properties inherited but here we don't have to use the &lt;strong&gt;this&lt;/strong&gt; keyword.&lt;/p&gt;

&lt;p&gt;NOTE: In ES6, we do not have to write a special line of code to inherit prototypes. as we already know, prototypes are accessible by all instances of the class object and so inherited by the extending class.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Lastly, let's talk about a special method available in ES6( &lt;strong&gt;static&lt;/strong&gt; Methods):
Static methods come in handy when we have methods that do not make use of argument passed into instantiate(create an instance) a copy of an object and we want all instances of the object to have it. for example, if we want all instances of the Person object to have a tag of 'human' we will write:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Person{
  constructor(firstName, lastName, age){
    this.firstName = firstName;
    this.lastName = lastName;    
    this.age = age;
  }

   getAge(){
     return `${this.firstName} ${this.lastName};   
   }   

   static isHuman(){
     return 'Is a Human'
   }
}

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

&lt;/div&gt;


&lt;p&gt;Just as simple as that. But mind you, Static methods are defined on the class itself, and not on the prototype.&lt;/p&gt;

&lt;p&gt;That means you cannot call a static method with the instance but with the class itself e.g calling the static method in our class above will be&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Person.isHuman();   
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  CONCLUSION:
&lt;/h1&gt;

&lt;p&gt;I know this article was long, but I believe you have understanding of Object in ES5 and ES6 syntax; what object prototype mean, how to inherit from objects in ES5 and ES6, as well as ES6 class features and syntax.&lt;/p&gt;

&lt;p&gt;Thank for reading, cheers!!!.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>es5</category>
      <category>es6</category>
      <category>oop</category>
    </item>
    <item>
      <title>How to Customize Bootstrap Theme using Sass.</title>
      <dc:creator>Origho Precious</dc:creator>
      <pubDate>Wed, 22 Apr 2020 13:26:31 +0000</pubDate>
      <link>https://dev.to/orighoprecious/how-to-customize-bootstrap-theme-using-sass-54a8</link>
      <guid>https://dev.to/orighoprecious/how-to-customize-bootstrap-theme-using-sass-54a8</guid>
      <description>&lt;p&gt;Hello there, my name is Precious. I'm a frontend developer from Nigeria and this is my first article.&lt;/p&gt;

&lt;p&gt;Bootstrap is a very awesome front-end library used to build responsive, mobile-first projects on the web. It is the world’s most popular front-end component library. A lot of us developers have made use of bootstrap either slightly or heavily in our projects especially for prototyping or when building demo projects, It is very useful and easy to implement but sometimes we wish we could edit some of bootstrap pre-built theme classes to our preference. For example, the primary color in our project is not the default primary-color(blue) in bootstrap and we wish we could just change it to our own project color to make our work easier, This can actually be achieved using the CSS pre-processor called sass. &lt;/p&gt;

&lt;p&gt;To follow up with this article you need to have a basic understanding of &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How SASS works,&lt;/li&gt;
&lt;li&gt;What variables are, &lt;/li&gt;
&lt;li&gt;What are partials and &lt;/li&gt;
&lt;li&gt;How to compile SASS.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note: this is not a hack. &lt;br&gt;
It is supported by the Bootstrap Team and included in their documentation under theming, you can check on it using this &lt;a href="https://getbootstrap.com/docs/4.4/getting-started/theming/"&gt;link&lt;/a&gt; &lt;/p&gt;
&lt;h1&gt;
  
  
  How it works
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;In a summary, we will override their default styles set up in their SASS code and recompile it into our own CSS code which we will use in our project.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Steps:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;You need bootstrap in your local project file which we can get either by installing it with a package manager or by downloading the source files not the compiled CSS files from the official bootstrap but here we will be working with Bootstrap installed using a package manager(npm).&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;How to install Bootstrap using NPM&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;You need node installed, so download node from &lt;a href="https://nodejs.org/en/"&gt;here&lt;/a&gt; if you don't have it installed yet.&lt;/li&gt;
&lt;li&gt;After installation, open the terminal in your text editor. In VScode use

&lt;code&gt;ctrl + ~ 
&lt;/code&gt;

(a shortcut). Then Initialize npm in your project using

&lt;code&gt;npm init&lt;/code&gt;

follow the prompt by just clicking

&lt;code&gt;enter&lt;/code&gt;

till the end. Install bootstrap with

&lt;code&gt;npm install bootstrap&lt;/code&gt;

and you're done!&lt;/li&gt;
&lt;/ul&gt;

&lt;ul&gt;
&lt;li&gt;After installing Bootstrap, create an scss folder in your project directory and inside it a file for your custom SASS codes. The files should be structured like this:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9CUnDf6u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4omszet5kiph7q628paf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9CUnDf6u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4omszet5kiph7q628paf.png" alt="File structure after installing with package manager"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;NOTE: The SCSS folder in the above image is the one created by you. &lt;br&gt;
Your project folder has to be structured that way to work so make sure you have your files set in the format.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you check the

&lt;code&gt;node_modules&lt;/code&gt;

folder in your text editor and then open the

&lt;code&gt;scss&lt;/code&gt;

folder, you will see the sass code files used for each component of bootstrap. You might be tempted to edit but don't it won't work simply because it won't be compiled into CSS. Instead, we will override them in our custom sass file.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By now, your custom Sass codes should be linked to compile into CSS. Which you should know how to do by now if you understand Sass.  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;They are two things you can do here, 
(a) Import all the bootstrap files in one as a partial in our custom sass file e.g
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@import "../node_modules/bootstrap/scss/bootstrap";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;(b) Import the sass files of the bootstrap components you used in your project into your custom sass file but in this method, they are 3 files we must import, these are the function, variables, and mixin files. For example, if you used bootstrap grid in your project. you will import the sass grid partial and the required 3 mentioned above like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Required
@import "../node_modules/bootstrap/scss/functions";
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";

// Used
@import "../node_modules/bootstrap/scss/grid";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To know which file to import you can check your project and the bootstrap scss folder in node_module folder to see how the files are named.&lt;/p&gt;

&lt;p&gt;The first method is preferred so that you can effectively import all of bootstrap styles once but for performance it's makes loading slow but if you import the files you used in your project, it loads the webpage faster. So if you are sticking with the second method be careful to import all the files you used.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Customizing The styles:
NOTE: All your sass codes to override the bootstrap default codes should be above the partials you imported i.e
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Your code
$body-bg: #000;
$body-color: #111;

// Bootstrap file partials
@import "../node_modules/bootstrap/scss/bootstrap";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We can override colors like this e.g
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Bootstrap default code
$theme-colors: (
  "primary": #0074d9,
  "danger": #ff4136
);

// Our Custom sass code
$theme-colors: (
  "primary": green,
  "danger": coral
);

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

&lt;/div&gt;



&lt;p&gt;What we did above is using the same theme-color map that was used in their code(variables.scss) and we changed the values of the variable. This is to say w can customize everything in the variables folder by simply looking at how they are structured and use the same pattern in our sass file but change the values to our preference. We can also set our own color themes like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// You can put your desired name in place of 'the custom-color' and your desired color as the value
$theme-colors: (
  "custom-color": #red
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;For example, we can customize the default container max-widths by doing this:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// How bootstrap structured theirs in their variable.scss file
$container-max-widths: (
  sm: 540px,
  md: 720px,
  lg: 960px,
  xl: 1140px
) !default;

// Ours in our scss file
$container-max-widths: (
  sm: 500px,
  md: 768px,
  lg: 920px,
  xl: 1140px
);

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

&lt;/div&gt;



&lt;p&gt;In your sass file it should look like this:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jpZvVK1X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cieggehx28z36nh2p926.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jpZvVK1X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cieggehx28z36nh2p926.png" alt="Your sass file"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;Following the examples stated in the article, you can customize bootstrap theme to your preference.&lt;/p&gt;

&lt;p&gt;This is my very first article. If you find it interesting and educative please leave a like to cheer me up. Thanks!&lt;/p&gt;

</description>
      <category>bootstrap</category>
      <category>sass</category>
      <category>css</category>
      <category>scss</category>
    </item>
  </channel>
</rss>
