<?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: Ibukun Folay</title>
    <description>The latest articles on DEV Community by Ibukun Folay (@ibukunfolay).</description>
    <link>https://dev.to/ibukunfolay</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%2F1061615%2Fae72f61f-1349-447c-9689-454ec4b2bcb3.jpeg</url>
      <title>DEV Community: Ibukun Folay</title>
      <link>https://dev.to/ibukunfolay</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ibukunfolay"/>
    <language>en</language>
    <item>
      <title>Building a React App with AWS: A Beginner-Friendly Guide</title>
      <dc:creator>Ibukun Folay</dc:creator>
      <pubDate>Mon, 20 Nov 2023 22:55:48 +0000</pubDate>
      <link>https://dev.to/ibukunfolay/building-a-react-app-with-aws-a-beginner-friendly-guide-40m3</link>
      <guid>https://dev.to/ibukunfolay/building-a-react-app-with-aws-a-beginner-friendly-guide-40m3</guid>
      <description>&lt;p&gt;Are you excited to enhance your React app by tapping into the potential of Amazon Web Services (AWS)? In this guide, we'll take a walk through the process of integrating AWS services with your React application. Whether you're a newcomer or have some experience with React, this step-by-step manual is crafted to help you seamlessly incorporate the capabilities of AWS into your web projects.&lt;/p&gt;

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

&lt;p&gt;Before we dive in, ensure you have the following:&lt;br&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Node.js and npm are installed on your machine.&lt;/li&gt;
&lt;li&gt;An AWS account. If you don't have one, you can sign up here.&lt;/li&gt;
&lt;li&gt;Create a new React app using create-react-app:
&lt;/li&gt;
&lt;/ol&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-react-app aws-react-app
cd aws-react-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;h1&gt;
  
  
  Setting Up AWS Amplify
&lt;/h1&gt;

&lt;p&gt; &lt;br&gt;
Let's kick things off by installing the Amplify CLI and initializing our project. AWS Amplify is a suite of tools and services designed to empower front-end developers to build full-stack applications.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g @aws-amplify/cli
amplify configure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt; &lt;br&gt;
Follow the prompts to configure your Amplify project with your AWS account credentials.&lt;br&gt;
 &lt;br&gt;
Now, let's initialize the Amplify project within our React app.&lt;br&gt;
&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;amplify init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt; &lt;br&gt;
Answer the questions prompted by the CLI to configure your project. For simplicity, choose the default options.&lt;br&gt;
 &lt;/p&gt;
&lt;h2&gt;
  
  
  Adding Authentication
&lt;/h2&gt;

&lt;p&gt; &lt;br&gt;
AWS Cognito, a fully managed authentication service, will be our choice for integrating authentication into our React app.&lt;br&gt;
&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;amplify add auth
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt; &lt;br&gt;
Configure user sign-up and sign-in preferences as prompted. Then, deploy the changes.&lt;br&gt;
&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;amplify push
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;h2&gt;
  
  
  Incorporating Storage with Amazon S3
&lt;/h2&gt;

&lt;p&gt; &lt;br&gt;
Amazon S3, a scalable object storage service, will be used to store and retrieve files in our React app.&lt;br&gt;
&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;amplify add storage
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt; &lt;br&gt;
Select "Content" as the type of storage and configure your storage bucket. Deploy the changes.&lt;br&gt;
&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;amplify push
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;h2&gt;
  
  
  Adding API Functionality with AWS AppSync
&lt;/h2&gt;

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

&lt;p&gt;AWS AppSync simplifies the development of GraphQL APIs, handling the heavy lifting of securely connecting to data sources.&lt;br&gt;
&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;amplify add api
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt; &lt;br&gt;
Choose "GraphQL" as the API type, configure your API, and deploy the changes.&lt;br&gt;
&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;amplify push
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;h1&gt;
  
  
  Integrating AWS Services into the React App
&lt;/h1&gt;

&lt;p&gt; &lt;br&gt;
Now that our AWS services are set up, let's seamlessly integrate them into our React app.&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;
&lt;h2&gt;
  
  
  Authentication Integration
&lt;/h2&gt;

&lt;p&gt; &lt;br&gt;
In your src/index.js file, import and configure the Amplify library:&lt;br&gt;
&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Amplify from 'aws-amplify';
import awsconfig from './aws-exports';

Amplify.configure(awsconfig);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt; &lt;br&gt;
Now, you can use the Amplify authentication module in your React components:&lt;br&gt;
&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { withAuthenticator } from 'aws-amplify-react';

function App() {
  // Your app logic here
}

export default withAuthenticator(App, { includeGreetings: true });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;h2&gt;
  
  
  Storage Integration
&lt;/h2&gt;

&lt;p&gt; &lt;br&gt;
For uploading and retrieving files from S3, use the following code:&lt;br&gt;
&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Storage } from 'aws-amplify';

// Upload a file
Storage.put('example.txt', 'Hello, AWS!')
  .then(result =&amp;gt; console.log('File uploaded:', result))
  .catch(err =&amp;gt; console.error('Error uploading file:', err));

// Retrieve a file
Storage.get('example.txt')
  .then(result =&amp;gt; console.log('File retrieved:', result))
  .catch(err =&amp;gt; console.error('Error retrieving file:', err));

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

&lt;/div&gt;



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

&lt;h2&gt;
  
  
  API Integration
&lt;/h2&gt;

&lt;p&gt; &lt;br&gt;
To integrate API functionality, use the following example to fetch data from your GraphQL API:&lt;br&gt;
&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { API } from 'aws-amplify';

async function fetchData() {
  try {
    const data = await API.graphql({ query: /* your GraphQL query here */ });
    console.log('Data fetched:', data);
  } catch (error) {
    console.error('Error fetching data:', error);
  }
}

// Call the function where needed
fetchData();

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

&lt;/div&gt;



&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt; &lt;br&gt;
Congratulations! You've successfully integrated AWS services into your React app using AWS Amplify. This guide covered the basics of authentication, storage, and API functionality. As you continue developing your app, explore the AWS Amplify documentation for more advanced features and customization options.&lt;/p&gt;

&lt;p&gt;Remember to adhere to coding best practices, such as organizing your code into modular components, handling errors gracefully, and optimizing for performance. Happy coding!&lt;/p&gt;

</description>
      <category>react</category>
      <category>aws</category>
      <category>amplify</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Build a Nodejs Server Using Firebase/Firestore (CRUD)</title>
      <dc:creator>Ibukun Folay</dc:creator>
      <pubDate>Sat, 22 Apr 2023 09:42:57 +0000</pubDate>
      <link>https://dev.to/ibukunfolay/build-a-nodejs-server-using-firebasefirestore-crud-2725</link>
      <guid>https://dev.to/ibukunfolay/build-a-nodejs-server-using-firebasefirestore-crud-2725</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In this article we would be looking at how to build a node js server using firebase and firestore.&lt;br&gt;
We would also be building the crud (Create, Read, Update, Delete) functionalities into our server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Topics to look out for in this article&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is node js and firebase?&lt;/li&gt;
&lt;li&gt;Setting up our project folder&lt;/li&gt;
&lt;li&gt;Installing neccessary dependencies&lt;/li&gt;
&lt;li&gt;Es6 setup (.babelrc)
&lt;/li&gt;
&lt;li&gt;Configuring firebase&lt;/li&gt;
&lt;li&gt;Setting up config files&lt;/li&gt;
&lt;li&gt;Create express server (index.js)&lt;/li&gt;
&lt;li&gt;Building our model&lt;/li&gt;
&lt;li&gt;Building crud functionalities (controllers)&lt;/li&gt;
&lt;li&gt;Routes&lt;/li&gt;
&lt;li&gt;Run server&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What is node js and firebase?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nodejs&lt;/strong&gt; is an open-source, cross-platform JavaScript runtime environment and library for running web applications outside the client's browser. Nodejs is used for building asynchronous &amp;amp; event-driven model backend servers. If you don’t have node js installed on your local machine, you can download it here.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Firebase&lt;/strong&gt; is a Backend-as-a-Service (BaaS) app development platform provided by google that hosts backend services such as a realtime database, cloud storage, authentication, crash reporting, machine learning, remote configuration, and hosting for your static files. &lt;br&gt;
 The service we would be using today from firebase is Firestore, which is the database provided by firebase. It is a no-sql document oriented database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setting up our project folder&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Firstly, we have to create a folder, in my case i’ll call it node-firebase but feel free to name it whatever. This would be our root working directory.&lt;/p&gt;

&lt;p&gt;Then in your terminal, run the following script: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;Npm init -y&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This should create a package.json file in the root of our folder.&lt;/p&gt;

&lt;p&gt;Next, in the root of our project folder we need to create the following files: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;index.js - this is the main file for our server&lt;/li&gt;
&lt;li&gt;firebase.js - this is where the database connection is initiated&lt;/li&gt;
&lt;li&gt;config.js - this contains all the necessary configuration to help maintain a clean working environment. I refer to this as the brain box file in any server.&lt;/li&gt;
&lt;li&gt;.env - this contains all our environment variables&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also create the following folders in the root of your project folder:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Controllers&lt;/li&gt;
&lt;li&gt;Models&lt;/li&gt;
&lt;li&gt;Routes &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Installing neccessary dependencies&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Run the scripts below to install the needed dependencies:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install express cors dotenv firebase&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install nodemon –save-dev&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Using –save-dev installs our &lt;em&gt;nodemon&lt;/em&gt; as a dev dependency&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Es6 setup (babel)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This will enable us to use the es6 syntax in writing our code.&lt;/p&gt;

&lt;p&gt;In our terminal we run the following script to install our babel packages as dev dependencies: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install @babel/core @babel/node @babel/cli @babel/preset-env –save-dev&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;after the dependencies are installed successfully, create a file .babelrc in the root of your project folder and add the code below:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;{&lt;br&gt;
  "presets": [["@babel/preset-env"]]&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;finally, in the package.json, add the line below:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"type": "module"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And we are good to go using the es6 syntax.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setting up firebase&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After our dependencies have been installed, we go to &lt;a href="https://console.firebase.google.com"&gt;firebase console&lt;/a&gt; a follow the steps below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click on add project&lt;/li&gt;
&lt;li&gt;Enter the name of the project &lt;/li&gt;
&lt;li&gt;We can turn off analytics for this project.&lt;/li&gt;
&lt;li&gt;Click create project&lt;/li&gt;
&lt;li&gt;Click on the code button &lt;/li&gt;
&lt;li&gt;Enter the name of the app and click on the register app button&lt;/li&gt;
&lt;li&gt;Click on cloud firestore (to create database)&lt;/li&gt;
&lt;li&gt;Click on setting and copy firebase configuration &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Setting up config files&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;.env file&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After sucessfully executing the steps above, in the root of your project folder, create a .env file and add the following code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PORT=5000
HOST=localhost
HOST_URL=http://localhost:5000




#firebase config
API_KEY=””
AUTH_DOMAIN=””
PROJECT_ID=””
STORAGE_BUCKET=””
MESSAGING_SENDER_ID=””
APP_ID=””
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace the strings with the firebase config details generated on your firebase console.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Config.js&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once you are done with the above, you can copy the code below into your config.js file in the root of your folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import dotenv from 'dotenv';
import assert from 'assert';

dotenv.config();

const {
  PORT,
  HOST,
  HOST_URL,
  API_KEY,
  AUTH_DOMAIN,
  PROJECT_ID,
  STORAGE_BUCKET,
  MESSAGING_SENDER_ID,
  APP_ID,
} = process.env;

assert(PORT, 'Port is required');
assert(HOST, 'Host is required');

export default {
  port: PORT,
  host: HOST,
  hostUrl: HOST_URL,
  firebaseConfig: {
    apiKey: API_KEY,
    authDomain: AUTH_DOMAIN,
    projectId: PROJECT_ID,
    storageBucket: STORAGE_BUCKET,
    messagingSenderId: MESSAGING_SENDER_ID,
    appId: APP_ID,
  },
};

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Firebase.js&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;In the firebase.js file add the following code to initialize our database:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { initializeApp } from 'firebase/app';
import config from './config.js';

const firebase = initializeApp(config.firebaseConfig);

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Create express server (index.js)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the index.js file, add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import express from 'express';
import cors from 'cors';

import config from './config.js';

const app = express();

app.use(cors());
app.use(express.json());


app.listen(config.port, () =&amp;gt;
  console.log(`Server is live @ ${config.hostUrl}`),
);

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

&lt;/div&gt;



&lt;p&gt;If we run &lt;code&gt;npm start&lt;/code&gt; our server should be up and running.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Building our model&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create a file named productModel.js in your model folder and add the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Product {
  constructor(id, name, price, retailer, amountInStock) {
    (this.id = id),
      (this.name = name),
      (this.price = price),
      (this.retailer = retailer),
      (this.amountInStock = amountInStock);
  }
}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Building crud functionalities (controllers)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Crud stands for Create, Read, Update and Delete. These are the foundations on which an api is built.&lt;/p&gt;

&lt;p&gt;In the controllers folder, create a file named productControllers.js and add the following blocks of code respectively:&lt;/p&gt;

&lt;p&gt;At the top :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import firebase from '../firebase.js';
import Product from '../models/productModel.js';
import {
  getFirestore,
  collection,
  doc,
  addDoc,
  getDoc,
  getDocs,
  updateDoc,
  deleteDoc,
} from 'firebase/firestore';

const db = getFirestore(firebase);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create product function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const createProduct = async (req, res, next) =&amp;gt; {
  try {
    const data = req.body;
    await addDoc(collection(db, 'products'), data);
    res.status(200).send('product created successfully');
  } catch (error) {
    res.status(400).send(error.message);
  }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Get all products function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const getProducts = async (req, res, next) =&amp;gt; {
  try {
    const products = await getDocs(collection(db, 'products'));
    const productArray = [];

    if (products.empty) {
      res.status(400).send('No Products found');
    } else {
      products.forEach((doc) =&amp;gt; {
        const product = new Product(
          doc.id,
          doc.data().name,
          doc.data().price,
          doc.data().retailer,
          doc.data().amountInStock,
        );
        productArray.push(product);
      });

      res.status(200).send(productArray);
    }
  } catch (error) {
    res.status(400).send(error.message);
  }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Get product by id:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const getProduct = async (req, res, next) =&amp;gt; {
  try {
    const id = req.params.id;
    const product = doc(db, 'products', id);
    const data = await getDoc(product);
    if (data.exists()) {
      res.status(200).send(data.data());
    } else {
      res.status(404).send('product not found');
    }
  } catch (error) {
    res.status(400).send(error.message);
  }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update product by id:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const updateProduct = async (req, res, next) =&amp;gt; {
  try {
    const id = req.params.id;
    const data = req.body;
    const product = doc(db, 'products', id);
    await updateDoc(product, data);
    res.status(200).send('product updated successfully');
  } catch (error) {
    res.status(400).send(error.message);
  }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And finally, the delete product function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const deleteProduct = async (req, res, next) =&amp;gt; {
  try {
    const id = req.params.id;
    await deleteDoc(doc(db, 'products', id));
    res.status(200).send('product deleted successfully');
  } catch (error) {
    res.status(400).send(error.message);
  }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Routes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In our routes folder, create a file named productRoute.js and code the file below to it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import express from 'express';

import {
  createProduct,
  getProduct,
  getProducts,
  updateProduct,
  deleteProduct,
} from '../controllers/productController.js';

const router = express.Router();

router.get('/', getProducts);
router.post('/new', createProduct);
router.get('/product/:id', getProduct);
router.put('/update/:id', updateProduct);
router.delete('/delete/:id', deleteProduct);

export default router;

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

&lt;/div&gt;



&lt;p&gt;In order to get access to this route, we have to update our index.js file:&lt;/p&gt;

&lt;p&gt;Import the product route file:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import productRoute from './routes/productRoute.js';&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Initialize the route:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;app.use('/api', productRoute);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Our final index.js should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import express from 'express';
import cors from 'cors';

import config from './config.js';
import productRoute from './routes/productRoute.js';

const app = express();

app.use(cors());
app.use(express.json());

//routes
app.use('/api', productRoute);

app.listen(config.port, () =&amp;gt;
  console.log(`Server is live @ ${config.hostUrl}`),
);

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Run server&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In order to run the our nodejs-firebase server; &lt;/p&gt;

&lt;p&gt;We have to add the start command to our scripts in package.json:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"start": "nodemon index.js"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After this, in our terminal we can run the server command using:&lt;/p&gt;

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

&lt;p&gt;You can now use postman to ensure your api’s are working fine and also see the created files in your firestore database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At the end of this article, you should be able to create a working Nodejs server with firebase. &lt;/p&gt;

&lt;p&gt;Here's a &lt;a href="https://github.com/ibukunfolay/node-firebase"&gt;link&lt;/a&gt; to the source code on github.&lt;/p&gt;

&lt;p&gt;Happy coding.&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>firebase</category>
    </item>
    <item>
      <title>How to Build a Chrome Extension using React and Tailwindcss</title>
      <dc:creator>Ibukun Folay</dc:creator>
      <pubDate>Tue, 11 Apr 2023 15:37:06 +0000</pubDate>
      <link>https://dev.to/ibukunfolay/how-to-build-a-chrome-extension-using-react-and-tailwindcss-55pa</link>
      <guid>https://dev.to/ibukunfolay/how-to-build-a-chrome-extension-using-react-and-tailwindcss-55pa</guid>
      <description>&lt;p&gt;Here we would discuss how to create a basic chrome extension using React, Vite (bundler) and TailwindCss.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Things to look out for in this process&lt;/strong&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;What are extensions?&lt;/li&gt;
&lt;li&gt;Create react app&lt;/li&gt;
&lt;li&gt;Setup tailwindcss for styling&lt;/li&gt;
&lt;li&gt;Manifest.json&lt;/li&gt;
&lt;li&gt;Building the extension&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;What are browser extensions?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;According to &lt;a href="https://g.co/kgs/fVnDVU" rel="noopener noreferrer"&gt;wikipedia&lt;/a&gt;, a browser extension is a small software module for customizing a web browser. Browsers typically allow a variety of extensions, including user interface modifications, cookie management, ad blocking, and the custom scripting and styling of web pages.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create React App&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We can use the conventional create react app to setup our project folder, However, we would be using Vite.js to setup our project files.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://vitejs.dev/" rel="noopener noreferrer"&gt;Vite &lt;/a&gt;is a build tool created by Evan You, the creator of Vue. It allows for faster development thanks to super fast &lt;a href="https://webpack.js.org/concepts/hot-module-replacement/" rel="noopener noreferrer"&gt;Hot Module Reload&lt;/a&gt; (HMR), fast cold start times, and CSS + JSX + TypeScript support out of the box. &lt;a href="https://www.gpmd.co.uk/blog/what-is-vite-and-why-do-you-need-it" rel="noopener noreferrer"&gt;Click here to read more&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can run either of the following commands to setup our project folder:&lt;/p&gt;

&lt;p&gt;Using create-react-app&lt;/p&gt;

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

npx create-react-app my-app --template chrome-extension-app 


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

&lt;/div&gt;
&lt;p&gt;Using Vite&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

npm create vite@latest chrome-extension-app -- --template react


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

&lt;/div&gt;
&lt;p&gt;After running the create vite command successfully, you should see a few commands as shown below: &lt;/p&gt;

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

&lt;p&gt;Run the above commands to get your server started.&lt;/p&gt;

&lt;p&gt;This is what your project folder should look like.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Set up Tailwind Css&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Run the following commands in the root of the project folder:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p


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

&lt;/div&gt;
&lt;p&gt;To get tailwind working we need to update the tailwind.config.js file in the root of the project folder&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

/** @type {import('tailwindcss').Config} */
export default {
  content: ['./index.html', './src/**/*.{js,ts,jsx,tsx}'],
  theme: {
    extend: {},
  },
  plugins: [],
};


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

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

&lt;p&gt;Finally, add the following at the top of src/index.css file&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

@tailwind base;
@tailwind components;
@tailwind utilities;



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

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;The Manifest.json&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For our extension to work,we must update the manifest.json file. Vite does not come with a manifest.json file in the template, so we can create one in the public folder.&lt;/p&gt;

&lt;p&gt;After creating the file, add the following lines of code:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

{
  "name": "First Extensions",
  "description": "Basic Chrome Extension",
  "version": "1.0",
  "manifest_version": 2,
  "browser_action": {
    "default_popup": "index.html",
    "default_title": "My first extension"
  },
  "icons": {
    "16": "react.png",
    "48": "react.png",
    "128": "react.png"
  },
  "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
}


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

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Default_popup&lt;/strong&gt;: is the target file we want to render when our extension is loaded&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Default_title&lt;/strong&gt;: is the tooltip display that tells the user what we will see when the extensions opened&lt;/p&gt;

&lt;p&gt;By default, Create React App will embed the runtime script into index.html during the production build. This is done to limit the number of http requests.&lt;br&gt;
We will turn off this embedding behavior by adding: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;INLINE_RUNTIME_CHUNK= false&lt;/code&gt; before the build script in our package.json. &lt;/p&gt;

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

&lt;p&gt;Or as in our use case adding the line below to the manifest.json:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Building the extension&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After updating our manifest.json, we can now run the build script using: &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

npm run build


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

&lt;/div&gt;
&lt;p&gt;Once the build is finished we notice a new folder called "build" or "dist" in the root of our project. This is the folder we’ll load onto chrome as our extension.&lt;/p&gt;

&lt;p&gt;To load our extension on chrome, you can enter the url below in the address bar:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;chrome://extensions/&lt;/code&gt;&lt;/p&gt;

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

&lt;p&gt;Click the load unpacked button at the top left corner and select the build/dist folder in the root folder of our extension.&lt;/p&gt;

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

&lt;p&gt;Once you’re done you can click update to update all extensions and c'est fini.&lt;/p&gt;

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

&lt;p&gt;Just like that you can see your first chrome extension.&lt;/p&gt;

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

&lt;p&gt;You can now load your extension in-browser and test it out or better still tweak it to suit a specific purpose.&lt;/p&gt;

&lt;p&gt;To better explore possibilities with creating extensions, you can check out &lt;a href="https://medium.com/@artem-diashkin" rel="noopener noreferrer"&gt;Artem Diashkin's&lt;/a&gt; post below&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="https://medium.com/litslink/how-to-create-google-chrome-extension-using-react-js-5c9e343323ff" class="ltag__link__link" rel="noopener noreferrer"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fv2%2Fresize%3Afill%3A88%3A88%2F1%2A22KJAJNhNyn9sRyS9jl7zg.jpeg" alt="Artem Diashkin"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://medium.com/litslink/how-to-create-google-chrome-extension-using-react-js-5c9e343323ff" class="ltag__link__link" rel="noopener noreferrer"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;How To Create A Google Chrome Extension With React | by Artem Diashkin | LITSLINK | Medium&lt;/h2&gt;
      &lt;h3&gt;Artem Diashkin ・ &lt;time&gt;Jul 16, 2021&lt;/time&gt; ・ 
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fmedium-f709f79cf29704f9f4c2a83f950b2964e95007a3e311b77f686915c71574fef2.svg" alt="Medium Logo"&gt;
        Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At the end of this tutorial, you should be able to create a basic chrome extension with react and tailwindcss. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ibukunfolay/chrome-extension-app" rel="noopener noreferrer"&gt;Click here&lt;/a&gt; to see the full source code.&lt;/p&gt;

&lt;p&gt;Happy coding ✨.&lt;/p&gt;

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