<?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: Md. Khalid Hossen </title>
    <description>The latest articles on DEV Community by Md. Khalid Hossen  (@khalid7487).</description>
    <link>https://dev.to/khalid7487</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%2F956214%2F07945ffd-4ebc-42d0-8d4e-c6c8ea0390de.jpeg</url>
      <title>DEV Community: Md. Khalid Hossen </title>
      <link>https://dev.to/khalid7487</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/khalid7487"/>
    <language>en</language>
    <item>
      <title>Git Branching Strategy</title>
      <dc:creator>Md. Khalid Hossen </dc:creator>
      <pubDate>Sat, 26 Apr 2025 13:55:37 +0000</pubDate>
      <link>https://dev.to/khalid7487/git-branching-strategy-c31</link>
      <guid>https://dev.to/khalid7487/git-branching-strategy-c31</guid>
      <description>&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;This document will provide information about the software development processes, both for local development as well as the branching, tagging and pipeline running for our CI / CD workflow. This will be a living document to be updated as processes evolve to suit our needs. The goal is to keep things as simple as possible for developers while maintaining security in and a high standard of software delivered.&lt;/p&gt;

&lt;h2&gt;
  
  
  GitHub Branching Strategy
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Classic Gitflow&lt;/strong&gt;&lt;br&gt;
Gitflow is an alternative Git branching model that involves the use of feature branches and multiple primary branches. Under this model, developers create a feature branch and delay merging it to the main trunk branch until the feature is complete. These long-lived feature branches require more collaboration to merge and have a higher risk of deviating from the trunk branch. They can also introduce conflicting updates.&lt;/p&gt;

&lt;p&gt;This workflow doesn’t add any new concepts or commands beyond what’s required for the &lt;a href="https://www.atlassian.com/git/tutorials/comparing-workflows/feature-branch-workflow" rel="noopener noreferrer"&gt;Feature Branch Workflow&lt;/a&gt;. Instead, it assigns very specific roles to different branches and defines how and when they should interact. In addition to feature branches, it uses individual branches for preparing, maintaining, and recording releases. Also developers get to leverage all the benefits of the Feature Branch Workflow: pull requests, isolated experiments, and more efficient collaboration.&lt;/p&gt;

&lt;p&gt;In addition, you may want to install a git-flow cli tool or create commands’ aliases.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Branching model&lt;/strong&gt;&lt;br&gt;
Our workflow uses two branches and tags to record the history of the project. The main branch stores the release history to the test environment, and the develop branch serves as an integration branch for features. Tags of the project store official releases history with proper versioning. Also, the presentation branch is used for the presentation environment and it is synced with the main branch.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Frjv8wdshm4goar1uustl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Frjv8wdshm4goar1uustl.png" alt=" " width="629" height="280"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Feature branches&lt;/strong&gt;&lt;br&gt;
Each new feature should reside in its own branch, which can be pushed to the central repository for backup/collaboration. But, instead of branching off of main, feature branches use develop as their parent branch. When the feature’s code and tests are complete, it gets merged back into develop. Developer starts working on code improvements, writing documentation, etc.&lt;/p&gt;

&lt;p&gt;Feature branches are generally created off to the latest develop branch and should never interact directly with main.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F9sk5e70po2fwiju519gk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F9sk5e70po2fwiju519gk.png" alt=" " width="629" height="363"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Creating a feature branch with git (at this moment you may want to start creating aliases 🙂):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;git checkout develop&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;git pull&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;git checkout -b feature/new_feature_name&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you’re done with the development on the feature and test code is implemented, the next step is to merge the feature/new_feature_name into develop in the GitLab and assign a person to review your code or ask someone for help by mentioning in the comments. Do not forget to mark your branch for deletion after successful merge and squash commits into one!&lt;/p&gt;

&lt;p&gt;Encapsulating feature development also makes it possible to leverage pull requests, which are a way to initiate discussions around a branch. They give other developers the opportunity to sign off on a feature before it gets integrated into the official project. Or, if you get stuck in the middle of a feature, you can open a pull request asking for suggestions from your colleagues. The point is, pull requests make it incredibly easy for your team to comment on each other’s work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hotfix branches&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Maintenance or “hotfix” branches are used to quickly patch production releases. Hotfix branches are a lot like release branches and feature branches except they're based on main instead of develop. This is the only branch that should fork directly off of main. As soon as the fix is complete, it should be merged into both main and develop (or the current release branch if fix has a medium or low priority), and main should be tagged with an updated version number.&lt;/p&gt;

&lt;p&gt;When merging hotfix branches back into the main branch, the same procedure with the responsible person and reviewer has to be followed: deployment checklist, test prelive/live environments!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fo0jn17n9f72ktlnowgzv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fo0jn17n9f72ktlnowgzv.png" alt=" " width="629" height="460"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Having a dedicated line of development for bug fixes lets your team address issues without interrupting the rest of the workflow or waiting for the next release cycle. You can think of maintenance branches as ad hoc release branches that work directly with main. A hotfix branch can be created using the following methods:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;git checkout main&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;git pull&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;git checkout -b hotfix/bug_name&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Resolving conflicts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When many people are working on a project, conflicts may occasionally arise when merging the code of a new feature. If you follow the strategy described above for working with branches, the chance of unpredictable and complex conflicts is minimal. But can still happen in several cases: when merging many features into develop at once and merging hotfix branches into develop. As you will see, we won’t expect any other kind of conflicts in this strategy!&lt;/p&gt;

&lt;p&gt;Let's look at conflict resolution in a simple example with several new features being worked on at the same time. We'll also see that this conflict resolution also works when we merge the hotfix branches. &lt;/p&gt;

&lt;p&gt;You are working carefully with our branching strategy on a new Feature 3. Your co-workers just completed and merged Feature 1 and Feature 2 into develop, it is important that each feature was squashed into one commit in MR. For example, they developed small features using existing components and you had a bigger task on refactoring these components. You will probably have a conflict when you try to merge your changes into develop. To solve this problem and leave the Git history clean, you need to apply rebasing. In short, this functionality allows you to apply missed commits incrementally on top of your code. You can do it using following commands:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;git checkout develop&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;git pull&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;git checkout feature/your-feature-name&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;git rebase develop&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To resolve the conflict when merging hotfix branches, you just need to change the last checkout command with your hotfix branch name.&lt;/p&gt;

&lt;p&gt;After executing these commands in our example, you had to resolve the merge conflicts from Feature 1, then from Feature 2 (or vica-versa, if Feature 2 was merged before Feature 1). Git will add merge commits into your branch history and then you can merge Feature 3 into develop without any conflicts! Moreover, our git history remains clean and easy to revert in extreme situations.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Difference between promise and observable</title>
      <dc:creator>Md. Khalid Hossen </dc:creator>
      <pubDate>Sat, 01 Feb 2025 07:39:28 +0000</pubDate>
      <link>https://dev.to/khalid7487/difference-between-promise-and-observable-59o0</link>
      <guid>https://dev.to/khalid7487/difference-between-promise-and-observable-59o0</guid>
      <description>&lt;p&gt;Promises and Observables are both used to handle asynchronous operations in JavaScript, but they have key differences in how they work and their capabilities. Here's a breakdown:&lt;/p&gt;

&lt;h2&gt;
  
  
  Promises
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Definition:&lt;/strong&gt; A Promise represents a single future value or the eventual completion (or failure) of an asynchronous operation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Execution:&lt;/strong&gt; A Promise is eager, meaning it executes immediately when created.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Value Handling:&lt;/strong&gt; A Promise can only handle a single value or error. Once resolved or rejected, it cannot emit multiple values.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chaining:&lt;/strong&gt; You can chain .then() and .catch() methods to handle the resolved value or error.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cancellation:&lt;/strong&gt; Promises cannot be canceled once they are initiated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Case:&lt;/strong&gt; Ideal for one-time asynchronous operations like fetching data from an API.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const promise = new Promise((resolve, reject) =&amp;gt; {
  setTimeout(() =&amp;gt; resolve("Data fetched!"), 1000);
});

promise.then((result) =&amp;gt; console.log(result)); // Output: "Data fetched!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Observables
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Definition:&lt;/strong&gt; An Observable represents a stream of values over time. It can emit multiple values, errors, or a completion signal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Execution:&lt;/strong&gt; Observables are lazy, meaning they only execute when you subscribe to them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Value Handling:&lt;/strong&gt; Observables can emit multiple values over time, making them suitable for handling streams of data (e.g., user input, WebSocket messages).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chaining:&lt;/strong&gt; You can use operators like map, filter, and merge to transform or combine streams.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cancellation:&lt;/strong&gt; Observables can be canceled using the unsubscribe() method, which stops the stream.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Case:&lt;/strong&gt; Ideal for handling continuous or multiple asynchronous events, such as real-time data streams or user interactions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Observable } from 'rxjs';

const observable = new Observable((subscriber) =&amp;gt; {
  subscriber.next("First value");
  setTimeout(() =&amp;gt; subscriber.next("Second value"), 1000);
  setTimeout(() =&amp;gt; subscriber.complete(), 2000);
});

const subscription = observable.subscribe({
  next: (value) =&amp;gt; console.log(value), // Output: "First value", then "Second value"
  complete: () =&amp;gt; console.log("Completed!"),
});

subscription.unsubscribe(); // Cancel the subscription
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  When to Use Which?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Use a Promise when you need to handle a single asynchronous operation (e.g., fetching data from an API).&lt;/li&gt;
&lt;li&gt;Use an Observable when dealing with multiple values over time or continuous streams of data (e.g., real-time updates, user input events).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Observables are more powerful and flexible, but Promises are simpler and sufficient for many use cases.&lt;/p&gt;

</description>
      <category>observable</category>
      <category>promise</category>
      <category>promisevsobservable</category>
      <category>promiseandobservable</category>
    </item>
    <item>
      <title>implementing Spin the wheel and win price in react js</title>
      <dc:creator>Md. Khalid Hossen </dc:creator>
      <pubDate>Tue, 28 Jan 2025 11:52:41 +0000</pubDate>
      <link>https://dev.to/khalid7487/implementing-spin-the-wheel-and-win-price-in-react-js-3436</link>
      <guid>https://dev.to/khalid7487/implementing-spin-the-wheel-and-win-price-in-react-js-3436</guid>
      <description>&lt;p&gt;Have you ever wanted to create a fun and interactive spin wheel for your web app? Whether it’s for a game, a giveaway, or just to add some flair to your project, a spin wheel can be a great addition. In this post, I’ll walk you through how I built a customizable spin wheel component using React and the &lt;code&gt;react-custom-roulette&lt;/code&gt; library.&lt;/p&gt;

&lt;h2&gt;
  
  
  What We’re Building
&lt;/h2&gt;

&lt;p&gt;We’re creating a SpinWheel component that:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Displays a spinning wheel with customizable options (e.g., percentages like "25%", "30%", etc.).&lt;/li&gt;
&lt;li&gt;Randomly selects a result when the wheel is spun.&lt;/li&gt;
&lt;li&gt;Allows you to customize the wheel’s appearance (colors, fonts, etc.).&lt;/li&gt;
&lt;li&gt;Provides a callback to handle the winning value when the wheel stops.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Code Walkthrough
&lt;/h2&gt;

&lt;p&gt;Let’s dive into the code and see how it all comes together.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dependencies&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First, you’ll need to install the react-custom-roulette library:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add react-custom-roulette
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The SpinWheel Component
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from "react";
import { Wheel } from "react-custom-roulette";

const SpinWheel = ({ setWiningValue }) =&amp;gt; {
  // Define the options for the wheel
  const data = [
    { option: "25%" },
    { option: "30%" },
    { option: "35%" },
    { option: "45%" },
    { option: "55%" },
    { option: "65%" },
    { option: "75%" },
  ];

  // State to control spinning and prize selection
  const [mustSpin, setMustSpin] = useState(false);
  const [prizeNumber, setPrizeNumber] = useState(0);

  // Handle the spin button click 
  const handleSpinClick = () =&amp;gt; {
    const newPrizeNumber = Math.floor(Math.random() * data.length);
    setPrizeNumber(newPrizeNumber);
    setMustSpin(true);
  };

  return (
    &amp;lt;div className="relative"&amp;gt;
      {/* Wheel Component */}
      &amp;lt;Wheel
        mustStartSpinning={mustSpin}
        prizeNumber={prizeNumber}
        data={data}
        fontSize={22}
        onStopSpinning={() =&amp;gt; {
          setMustSpin(false);
          setWiningValue(data[prizeNumber].option); // Pass the winning value to the parent
        }}
        backgroundColors={[
          "#FEC60D",
          "#0496BB",
          "#E42220",
          "#C5037E",
          "#444F96",
          "#F38F1D",
          "#058F5B",
        ]}
        textColors={["#ffffff"]}
      /&amp;gt;

      {/* Spin Button */}
      &amp;lt;div className="z-10 absolute top-[50%] left-[50%] translate-x-[-50%] translate-y-[-50%]"&amp;gt;
        &amp;lt;button
          onClick={handleSpinClick}
          className="bg-[#800080] text-white border-2 border-solid border-white w-[60px] h-[60px] rounded-full"
        &amp;gt;
          Spin
        &amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Key Features Explained
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Customizable Options&lt;/strong&gt;&lt;br&gt;
The data array defines the options displayed on the wheel. Each option is an object with an option property (e.g., { option: "25%" }). You can easily modify this array to include any text or values you want.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Randomized Result&lt;/strong&gt;&lt;br&gt;
When the user clicks the "Spin" button, the handleSpinClick function selects a random index from the data array and sets it as the prizeNumber. The wheel then spins and stops at the selected option.This is the hack we only allow price 3 three options as winpriz&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Callback for Winning Value&lt;/strong&gt;&lt;br&gt;
The setWiningValue prop is a callback function that receives the winning value when the wheel stops spinning. This allows you to handle the result in the parent component (e.g., display it, log it, etc.).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Customizable Appearance&lt;/strong&gt;&lt;br&gt;
The backgroundColors and textColors props let you customize the wheel’s appearance. You can also adjust the fontSize and other styles to match your design.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important Note:&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;If you want to customized win prize you need to modified below functions according to requirements.Let's say i only allow first three items as win prize during that time you need to modified prize calculations.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const handleSpinClick = () =&amp;gt; {&lt;br&gt;
    const newPrizeNumber = Math.floor(Math.random() * data.length);&lt;br&gt;
    setPrizeNumber(newPrizeNumber);&lt;br&gt;
    setMustSpin(true);&lt;br&gt;
  };&lt;/code&gt;&lt;/p&gt;

</description>
      <category>manuplatewinresult</category>
      <category>cutomizewinpredictions</category>
      <category>reactwheel</category>
      <category>spinwheelwinprice</category>
    </item>
    <item>
      <title>Implementing a QR Scanner and send request to backend using next js</title>
      <dc:creator>Md. Khalid Hossen </dc:creator>
      <pubDate>Mon, 23 Dec 2024 07:32:04 +0000</pubDate>
      <link>https://dev.to/khalid7487/implementing-a-qr-scanner-and-send-request-to-backend-using-next-js-3c7o</link>
      <guid>https://dev.to/khalid7487/implementing-a-qr-scanner-and-send-request-to-backend-using-next-js-3c7o</guid>
      <description>&lt;p&gt;In this article, I'll walk you through creating a QR scanner in Next.js using the &lt;code&gt;@yudiel/react-qr-scanner&lt;/code&gt; library. We'll integrate it with basic functionalities like selecting devices, pausing scans, and customizing tracker overlays.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Use @yudiel/react-qr-scanner?
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;@yudiel/react-qr-scanner&lt;/code&gt; library provides an easy-to-use interface for scanning various barcode and QR code formats. It supports custom overlays and multiple formats, making it versatile for different applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Familiarity with React and Next.js.&lt;/li&gt;
&lt;li&gt;A Next.js project setup.&lt;/li&gt;
&lt;li&gt;Install the library:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add @yudiel/react-qr-scanner
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;for local testing scanner you need to enabled below chrome flag:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;chrome://flags/#usafely-treat-insecure-origin-as-secure&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Note: go to chrome tab and then search &lt;strong&gt;usafely-treat-insecure-origin-as-secure&lt;/strong&gt; and enabled.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here’s the complete code for the scanner page in Next.js.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ScannerPage Component&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

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

import { useState } from "react";
import {
  Scanner,
  useDevices,
  outline,
  boundingBox,
  centerText,
} from "@yudiel/react-qr-scanner";

const styles = {
  container: {
    width: 400,
    margin: "auto",
  },
  controls: {
    marginBottom: 8,
  },
};

export default function ScannerPage() {
  const [deviceId, setDeviceId] = useState&amp;lt;string | undefined&amp;gt;(undefined);
  const [tracker, setTracker] = useState&amp;lt;string | undefined&amp;gt;("centerText");
  const [pause, setPause] = useState(false);

  const devices = useDevices();

  function getTracker() {
    switch (tracker) {
      case "outline":
        return outline;
      case "boundingBox":
        return boundingBox;
      case "centerText":
        return centerText;
      default:
        return undefined;
    }
  }

  const handleScan = async (data: string) =&amp;gt; {
    setPause(true);
    try {
      const response = await fetch(
        `your-api-url?code=${encodeURIComponent(data)}`
      );
      const result = await response.json();

      if (response.ok &amp;amp;&amp;amp; result.success) {
        alert("Success! Welcome to the conference.");
      } else {
        alert(result.message);
      }
    } catch (error: unknown) {
      console.log(error);
    } finally {
      setPause(false);
    }
  };

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;div style={styles.controls}&amp;gt;
        &amp;lt;select onChange={(e) =&amp;gt; setDeviceId(e.target.value)}&amp;gt;
          &amp;lt;option value={undefined}&amp;gt;Select a device&amp;lt;/option&amp;gt;
          {devices.map((device, index) =&amp;gt; (
            &amp;lt;option key={index} value={device.deviceId}&amp;gt;
              {device.label}
            &amp;lt;/option&amp;gt;
          ))}
        &amp;lt;/select&amp;gt;
        &amp;lt;select
          style={{ marginLeft: 5 }}
          onChange={(e) =&amp;gt; setTracker(e.target.value)}
        &amp;gt;
          &amp;lt;option value="centerText"&amp;gt;Center Text&amp;lt;/option&amp;gt;
          &amp;lt;option value="outline"&amp;gt;Outline&amp;lt;/option&amp;gt;
          &amp;lt;option value="boundingBox"&amp;gt;Bounding Box&amp;lt;/option&amp;gt;
          &amp;lt;option value={undefined}&amp;gt;No Tracker&amp;lt;/option&amp;gt;
        &amp;lt;/select&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;Scanner
        formats={[
          "qr_code",
          "micro_qr_code",
          "rm_qr_code",
          "maxi_code",
          "pdf417",
          "aztec",
          "data_matrix",
          "matrix_codes",
          "dx_film_edge",
          "databar",
          "databar_expanded",
          "codabar",
          "code_39",
          "code_93",
          "code_128",
          "ean_8",
          "ean_13",
          "itf",
          "linear_codes",
          "upc_a",
          "upc_e",
        ]}
        constraints={{
          deviceId: deviceId,
        }}
        onScan={(detectedCodes) =&amp;gt; {
          handleScan(detectedCodes[0].rawValue);
        }}
        onError={(error) =&amp;gt; {
          console.log(`onError: ${error}'`);
        }}
        styles={{ container: { height: "400px", width: "350px" } }}
        components={{
          audio: true,
          onOff: true,
          torch: true,
          zoom: true,
          finder: true,
          tracker: getTracker(),
        }}
        allowMultiple={true}
        scanDelay={2000}
        paused={pause}
      /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Code Explanation
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Device Selection:&lt;/strong&gt; Use useDevices to fetch the list of available video input devices.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Custom Tracker:&lt;/strong&gt; Provide visual guidance for users with overlays like outline, boundingBox, and centerText.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scan Handling:&lt;/strong&gt; Pause the scanner after detecting a QR code, and fetch API data for validation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scanner Configuration:&lt;/strong&gt; Customize scanner formats, overlays, and multiple QR codes handling.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>qrscanner</category>
      <category>scanandsendrequesttobackend</category>
      <category>sccanerdoesnotopenlocal</category>
      <category>scanandverifed</category>
    </item>
    <item>
      <title>Added rate limit in api enpoint in node express js</title>
      <dc:creator>Md. Khalid Hossen </dc:creator>
      <pubDate>Wed, 27 Nov 2024 16:18:23 +0000</pubDate>
      <link>https://dev.to/khalid7487/added-rate-limit-in-api-enpoint-in-node-express-js-ocb</link>
      <guid>https://dev.to/khalid7487/added-rate-limit-in-api-enpoint-in-node-express-js-ocb</guid>
      <description>&lt;h2&gt;
  
  
  Rate Limiting in Express: Protect Your API from Brute Force Attacks
&lt;/h2&gt;

&lt;p&gt;Rate limiting is an essential feature to safeguard your API against brute force attacks. It helps control the number of requests a user can make within a specific time frame. Implementing rate limiting in an Express application is simple, thanks to the &lt;strong&gt;express-rate-limit&lt;/strong&gt; package.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;At first you need to install:&lt;/strong&gt; &lt;code&gt;yarn add express-rate-limit&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Then create a middleware where you can limit your api request:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

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

export const rateLimiter = rateLimit({
  windowMs: 60 * 1000,
  max: 100,
  message: 'You have exceeded the 100 requests in 1 min limit!',
  standardHeaders: true,
  legacyHeaders: false,
})

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

&lt;/div&gt;



&lt;p&gt;In this example, users are allowed up to 100 requests per minute. If they exceed this limit, they’ll receive a message stating the limit has been reached. also include rate limit info in the &lt;code&gt;RateLimit-*&lt;/code&gt; headers and disable &lt;code&gt;X-RateLimit-*&lt;/code&gt; headers&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Then you need to add this middleware into **index&lt;/strong&gt; 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 express from 'express';
import { rateLimiter } from '@/middlewares/rateLimit';

const app = express();

// Apply the rate limiter middleware to all routes
app.use(rateLimiter);

// Your other middleware and routes go here...

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
With these steps, you’ve successfully added rate limiting to your Express application. This feature helps ensure your API remains protected from abuse while maintaining a smooth experience for legitimate users.&lt;/p&gt;

</description>
      <category>ratelimit</category>
      <category>limitrequest</category>
    </item>
    <item>
      <title>How to become backend node js engineers</title>
      <dc:creator>Md. Khalid Hossen </dc:creator>
      <pubDate>Wed, 27 Nov 2024 04:23:22 +0000</pubDate>
      <link>https://dev.to/khalid7487/how-to-become-backend-node-js-engineers-26km</link>
      <guid>https://dev.to/khalid7487/how-to-become-backend-node-js-engineers-26km</guid>
      <description></description>
      <category>node</category>
      <category>beginners</category>
      <category>backenddevelopment</category>
    </item>
    <item>
      <title>Multipart-from-data/ file send to backend as json file using axios.</title>
      <dc:creator>Md. Khalid Hossen </dc:creator>
      <pubDate>Wed, 20 Nov 2024 16:45:07 +0000</pubDate>
      <link>https://dev.to/khalid7487/multipart-from-data-send-to-backend-as-json-file-using-axios-5a1d</link>
      <guid>https://dev.to/khalid7487/multipart-from-data-send-to-backend-as-json-file-using-axios-5a1d</guid>
      <description>&lt;p&gt;can i send &lt;strong&gt;multipart/form-data&lt;/strong&gt; as json file without converting formdata before sending post request to backend. &lt;br&gt;
Yes, you can do that using axios instance you can send post request without convert your object to form data. After axios versions &lt;strong&gt;v0.27.0&lt;/strong&gt; automatic your json data as multipart form-data you do not need to take extra pressure for sending binary data. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fgk26sd3tu4sb7jcbpaz1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fgk26sd3tu4sb7jcbpaz1.png" alt="axios automatic parse json data" width="743" height="162"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You may check my implementaions below where i upload file as json objects.here, in data sections thumbnail is a file type data.&lt;br&gt;
&lt;/p&gt;

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

const postJsonFile = async () =&amp;gt; {
  const url = 'https://example.com/api/upload'; 

const data = {
    "title": "Title",
    "thumbnail":  { File {name: 'bkash.jpeg', lastModified: 
        1683520805146, lastModifiedDate: Mon May 08 2023 10:40:05 
        GMT+0600 (Bangladesh Standard Time), webkitRelativePath: 
        '', size: 43133, …}
        length: 
        1[[Prototype]]
        : 
        FileList
      }
    ,
    "description": "&amp;lt;p&amp;gt;Descriptions&amp;lt;/p&amp;gt;",
    "skill_level": [
        "BEGINNER",
        "ADVANCE"
    ],
    "demo_videos": [
        "https://youtu.be/PsaXRgCibfU"
    ]
}

  try {
    const response = await axios.post(url, data, {
      headers: {
        'Content-Type': 'multipart/form-data',
      },
     formSerializer: {
        // Ensures array indices are included in serialized keys
        indexes: true, 
      },
    });

    console.log('Response:', response.data);
  } catch (error) {
    console.error('Error:', error.response?.data || error.message);
  }
};

postJsonFile();

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

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; you may not need to add formSerializer but if your backend written on python during that time you need to serialize data from frontend otherwise it will not works properly Or you may need to added extra code into your backend.&lt;/p&gt;

&lt;p&gt;Learn more you may check: &lt;/p&gt;
&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
      &lt;div class="c-embed__body flex items-center justify-between"&gt;
        &lt;a href="https://axios-http.com/docs/multipart" rel="noopener noreferrer" class="c-link fw-bold flex items-center"&gt;
          &lt;span class="mr-2"&gt;axios-http.com&lt;/span&gt;
          

        &lt;/a&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;



</description>
      <category>sendimage</category>
      <category>jsonasmultipartdata</category>
      <category>jsonpostasfile</category>
      <category>sendfile</category>
    </item>
    <item>
      <title>Passing pros child to parent component in react typescript</title>
      <dc:creator>Md. Khalid Hossen </dc:creator>
      <pubDate>Tue, 19 Nov 2024 16:11:27 +0000</pubDate>
      <link>https://dev.to/khalid7487/passing-pros-child-to-parent-component-in-react-typescript-2kal</link>
      <guid>https://dev.to/khalid7487/passing-pros-child-to-parent-component-in-react-typescript-2kal</guid>
      <description>&lt;p&gt;Using simple hacks you can pass data from child to parent.though it is very simple but it have a lot of use case. It mostly use for creating core component. Let's say you want to create select component where you want to pass Custom items during that time it is very helpful. There is lot of case you need it. &lt;/p&gt;

&lt;p&gt;I have use simple hacked to pass data child to parent you may check my implementaitons below:&lt;br&gt;
&lt;/p&gt;

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

// Define the type for the options
type Option = {
  label: string;
  value: string;
};

// Props for the ChildClass component
interface ChildClassProps {
  // A function prop that takes an `Option` and returns a React node
  customItems: (option: Option) =&amp;gt; React.ReactNode;
}

const ParentClass: React.FC = () =&amp;gt; {
  return (
    &amp;lt;ChildClass
      customItems={(props: Option) =&amp;gt; (
        &amp;lt;div&amp;gt;
          &amp;lt;div&amp;gt;{props.value}&amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
      )}
    /&amp;gt;
  );
};

const ChildClass: React.FC&amp;lt;ChildClassProps&amp;gt; = ({ customItems }) =&amp;gt; {
  // Options array with objects that match the `Option` type
  const options: Option[] = [
    { label: "green", value: "green" },
    { label: "blue", value: "blue" },
    { label: "red", value: "red" },
    { label: "yellow", value: "yellow" },
  ];

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;span&amp;gt;Child class&amp;lt;/span&amp;gt;
      {/* Iterate over the options and call `customItems` to render the custom content */}
      {options.map((item, index) =&amp;gt; (
        &amp;lt;div key={index}&amp;gt;
          {customItems(item)}
        &amp;lt;/div&amp;gt;
      ))}
    &amp;lt;/div&amp;gt;
  );
};

export default ParentClass;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;ParentClass Component:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The ParentClass component passes a customItems function as a prop to ChildClass. This function specifies how each option should be rendered.here you can pass your custom component.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ChildClass Component:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The ChildClass component iterates over the options array and calls the customItems function for each option. This allows ParentClass to define custom rendering for the options.&lt;/p&gt;

</description>
      <category>prenttochild</category>
      <category>getdatafromchlid</category>
      <category>react</category>
      <category>customitem</category>
    </item>
    <item>
      <title>Configure tanstack router into vite project with authenticate routes, active routes.</title>
      <dc:creator>Md. Khalid Hossen </dc:creator>
      <pubDate>Sun, 17 Nov 2024 08:39:02 +0000</pubDate>
      <link>https://dev.to/khalid7487/configure-tanstack-router-into-vite-project-with-authenticate-routes-active-routes-2463</link>
      <guid>https://dev.to/khalid7487/configure-tanstack-router-into-vite-project-with-authenticate-routes-active-routes-2463</guid>
      <description>&lt;p&gt;Tanstack router is a file based routing systems like next js. routing is pretty easy to configure but you need to do it carefully. Otherwise, it will kill your energy. Enough talk lets start:&lt;br&gt;
you need to install: &lt;code&gt;yarn add @tanstack/react-router&lt;/code&gt; &lt;br&gt;
and you need to add dev dependency: &lt;code&gt;yarn add -D @tanstack/router-devtools @tanstack/router-plugin&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;At 1st you need to configure vite and make it confortable with the projects. please make perfectly otherwise layout systems may not work as it should. Navigate vite.config.ts file and flow my code below:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;import {TanStackRouterVite} from '@tanstack/router-plugin/vite'&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;import this into vite.config.ts file then add plugin after react():&lt;br&gt;
&lt;code&gt;TanStackRouterVite({&lt;br&gt;
      routeToken: 'layout',&lt;br&gt;
    }),&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now, you need change your &lt;strong&gt;main.tsx&lt;/strong&gt; file:&lt;br&gt;
here i have create with context and pass my authentications where for authenticated routes and i aslo create hooks with zustand for my authentications.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {StrictMode} from 'react'
import ReactDOM from 'react-dom/client'
import {createRouter, RouterProvider} from '@tanstack/react-router'


import './index.css'
import {routeTree} from './routeTree.gen'
import useAuthToken from './hooks/useAuthToken'


const rootElement = document.getElementById('root')!

const router = createRouter({
  routeTree,
  context: {authentication: undefined!},
})

declare module '@tanstack/react-router' {
  interface Register {
    router: typeof router
  }
}


function App() {
  const authentication = useAuthToken()
  return (
        &amp;lt;RouterProvider router={router} context={{authentication, canAccessPage}} /&amp;gt;
  )
}

if (!rootElement.innerHTML) {
  const root = ReactDOM.createRoot(rootElement)
  root.render(
    &amp;lt;StrictMode&amp;gt;
      &amp;lt;App /&amp;gt;
    &amp;lt;/StrictMode&amp;gt;,
  )
}

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

&lt;/div&gt;



&lt;p&gt;useAuthtoke hooks::&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {create} from 'zustand'
import {persist} from 'zustand/middleware'

type State = {
  authToken?: string
}

type Action = {
  setAuthToken: (token: string) =&amp;gt; void
  removeAuthToken: () =&amp;gt; void
}

export type AuthTokenProps = State &amp;amp; Action


const initialState: State = {
  authToken: undefined,
}

const useAuthToken = create&amp;lt;AuthTokenProps&amp;gt;()(
  persist(
    set =&amp;gt; ({
      ...initialState,
      setAuthToken: token =&amp;gt; {
        set({authToken: token})
      },
      removeAuthToken: () =&amp;gt; {
        set(initialState)
      },
    }),
    {
      name: 'auth',
    },
  ),
)

export default useAuthToken

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

&lt;/div&gt;



&lt;p&gt;Now, you need to configure your __root.tsx file you need to link context form here using createRootRouteWithContext becuase you need your context for authenticate routes :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import * as React from 'react'
import {Outlet, createRootRouteWithContext} from '@tanstack/react-router'

import {AuthTokenProps} from '@/hooks/useAuthToken'

type RouterContext = {
  authentication: AuthTokenProps
}

export const Route = createRootRouteWithContext&amp;lt;RouterContext&amp;gt;()({
  component: () =&amp;gt; (
    &amp;lt;React.Fragment&amp;gt;
      &amp;lt;Outlet /&amp;gt;
    &amp;lt;/React.Fragment&amp;gt;
  ),
})

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

&lt;/div&gt;



&lt;p&gt;Since we already know tanstack router is allow file based routing we need to create One file and One folder under routes folder. Folder and file structer will be like this:&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;routes&lt;br&gt;
| __root.tsx&lt;br&gt;
| _authenticated.tsx&lt;br&gt;
| _authenticated&lt;br&gt;
  | dashboard.tsx&lt;br&gt;
| login.tsx&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
Note: here _authenticated folder hold your authenticated routes and others routes will be your unauthenticated routes. here login is unauthenticate route and dashboard will be your authenticate route.&lt;/p&gt;

&lt;p&gt;Now you need to configure your layout file which is  &lt;strong&gt;_authenticated.tsx&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'
import {createFileRoute, Outlet, redirect} from '@tanstack/react-router'

export const Route = createFileRoute('/_authenticated')({
  beforeLoad: async ({context}) =&amp;gt; {
    const {authToken} = context.authentication
    if (!authToken) {
      throw redirect({to: '/login'})
    }
  },
  component: () =&amp;gt; (
      &amp;lt;React.Fragment&amp;gt;
          &amp;lt;div className='flex flex-1 h-[90vh] flex-col gap-4 p-4 pt-0 top-14 absolute w-full'&amp;gt;
            &amp;lt;Outlet /&amp;gt;
          &amp;lt;/div&amp;gt;
      &amp;lt;/React.Fragment&amp;gt;
  ),
})

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

&lt;/div&gt;



&lt;p&gt;Note: on beforeLoad is callback functions where you can get context which you have set early if authtoken is available during that time you can accesss dashboard otherwise it will redirect to login page. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Oh one things don't forget to add authtoken after login.&lt;/strong&gt;&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 Route = createFileRoute('/login/')({
  beforeLoad: async ({context}) =&amp;gt; {
    const {authToken} = context.authentication
    if (authToken) throw redirect({to: '/dashboard'})
  },
  component: LoginForm,
})
--------------------- after login in successfully you need to setAuthtoken and router invalidate ---------------------
    {
      setAuthToken(access) // here you will get 
      router.invalidate()
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now actives routes link for active link:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;Link 
 className='py-3 [&amp;amp;.active]:font-bold [&amp;amp;.active]:text-sky-500'
 to={subItem.url}
 activeOptions={{exact: true, includeSearch: false}}&amp;gt;
  Dashbaord
&amp;lt;/Link&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;here you need to pass &lt;strong&gt;exact: true&lt;/strong&gt; for exact path match if you have search query of that routes during that time you need to pass &lt;strong&gt;includeSearch: false&lt;/strong&gt; . Otherwise when you have added query in your path during that time active link will be deactiv because you have pass exact true.&lt;/p&gt;

</description>
      <category>tanstackrouter</category>
      <category>activeroutes</category>
      <category>tanstackrouterreact</category>
      <category>authenticateroutes</category>
    </item>
    <item>
      <title>Absoulate import in node express typescript project configrations.</title>
      <dc:creator>Md. Khalid Hossen </dc:creator>
      <pubDate>Sun, 03 Nov 2024 15:06:08 +0000</pubDate>
      <link>https://dev.to/khalid7487/absoulate-import-in-node-express-typescript-project-configrations-3le4</link>
      <guid>https://dev.to/khalid7487/absoulate-import-in-node-express-typescript-project-configrations-3le4</guid>
      <description>&lt;p&gt;If you want to enabled typescript express project for absoulate import and want remove &lt;strong&gt;../..&lt;/strong&gt; from entire project this guide for you:&lt;/p&gt;

&lt;p&gt;at first you need to configure &lt;strong&gt;tsconfig.json&lt;/strong&gt; file where you need to configure absoulate path. You can check below file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
{
    "compilerOptions": {
      "target": "ES2020",
      "module": "commonjs",
      "strict": true,
      "esModuleInterop": true,
      "skipLibCheck": true,
      "forceConsistentCasingInFileNames": true,
      "outDir": "./dist",
      "rootDir": "./src",
      "baseUrl": ".",
      "paths": {
        "*": ["node_modules/*"],
        "@/*": ["src/*"], 
      }
    },
    "include": ["./env.d.ts", "src/**/*.ts"],
    "exclude": ["node_modules"]
  }

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;&lt;br&gt;
here i have used path as @/* and src is my base url&lt;/p&gt;

&lt;p&gt;Then you need to add another library for configure this, &lt;strong&gt;tsconfig-paths&lt;/strong&gt; it and chage your running script then everything will be fine. &lt;/p&gt;

&lt;h2&gt;
  
  
  script should be like this:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
    "dev": "nodemon --watch src --exec ts-node --require tsconfig-paths/register --transpile-only src/main.ts",
  },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>absoulateimport</category>
      <category>enabledabsoulatlimport</category>
      <category>expresstypescriptconfig</category>
      <category>basepathimport</category>
    </item>
    <item>
      <title>Configure Eslint, Prettier and show eslint warning into running console vite react typescript project</title>
      <dc:creator>Md. Khalid Hossen </dc:creator>
      <pubDate>Thu, 06 Jun 2024 19:14:23 +0000</pubDate>
      <link>https://dev.to/khalid7487/configure-eslint-prettier-and-show-eslint-warning-into-running-console-vite-react-typescript-project-pk5</link>
      <guid>https://dev.to/khalid7487/configure-eslint-prettier-and-show-eslint-warning-into-running-console-vite-react-typescript-project-pk5</guid>
      <description>&lt;p&gt;Creating a React application with Vite has become the preferred way over using create-react-app due to its faster and simpler development environment.Although vite projects by default offer eslint support but it is very simple setup which is not very helpful so far.&lt;/p&gt;

&lt;p&gt;In this guide this i will go through config eslint with prettier groups import ad show eslint warning into console in react + typescript which is create by vite.&lt;/p&gt;

&lt;p&gt;Assuming you already have your React Vite project set up (using npm create vite@latest), the first step is to install Vitest:&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up Vite eslint with yarn install:
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;yarn add  eslint-import-resolver-typescript eslint-plugin-import eslint-plugin-prettier eslint-plugin-react-refresh prettier typescript-eslint&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  For showing eslint and typescript error and warning into console we need to add another library below:
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;yarn add vite-plugin-checker&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now time to update &lt;strong&gt;tsconfig.json&lt;/strong&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "compilerOptions": {
    "target": "ES2020",
    "useDefineForClassFields": true,
    "lib": ["ES2020", "DOM", "DOM.Iterable"],
    "module": "ESNext",
    "skipLibCheck": true,
    "baseUrl": "src",
    "paths": {
      "*": ["*"]
    },
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noFallthroughCasesInSwitch": true
  },
  "include": ["src", "vite.config.ts"],
  "exclude": [
    "node_modules",
    "./node_modules",
    "./node_modules/*",
    "./node_modules/@types/node/index.d.ts"
  ],
  "references": [{"path": "./tsconfig.node.json"}]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: Here, i added basurl as src and and path accept whatever i have set in vite.config.ts. For example, I have a folder name component and &lt;a class="mentioned-user" href="https://dev.to/core"&gt;@core&lt;/a&gt; folder now i want to import it as same group during that time it will be helpful.&lt;/p&gt;

&lt;p&gt;Enough talk let's configure &lt;strong&gt;vite.config.ts&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
import {defineConfig} from 'vite'
import react from '@vitejs/plugin-react'
import checker from 'vite-plugin-checker'

export default defineConfig({
  plugins: [
    react(),
    checker({
      typescript: true,
      eslint: {
        lintCommand: 'eslint "./src/**/*.{ts,tsx}"',
      },
    }),
  ],
  resolve: {
    alias: {
      images: '/src/images',
      component: '/src/component',
      '@core': '/src/@core',
    },
  },
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now we need to update &lt;strong&gt;.eslintrc.cjs&lt;/strong&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = {
  root: true,
  env: {browser: true, es2020: true},
  extends: [
    'eslint:recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:react-hooks/recommended',
  ],
  parserOptions: {
    project: './tsconfig.json',
    tsconfigRootDir: __dirname,
  },
  ignorePatterns: ['dist', '.eslintrc.cjs'],
  parser: '@typescript-eslint/parser',
  plugins: ['react-refresh', 'import', 'prettier', 'react', '@typescript-eslint'],
  rules: {
    'react-refresh/only-export-components': ['warn', {allowConstantExport: true}],
    'no-console': 'warn',
    'arrow-body-style': ['warn', 'as-needed'],
    'no-empty-function': 'error',
    quotes: ['warn', 'single', {avoidEscape: true}],
    'prefer-const': 'off',
    'no-dupe-keys': 'warn',
    'react/react-in-jsx-scope': ['off'],
    'no-duplicate-imports': ['warn'],
    '@typescript-eslint/no-unused-vars': ['warn'],
    '@typescript-eslint/no-explicit-any': ['error'],
    'valid-typeof': ['error', {requireStringLiterals: true}],
    'prettier/prettier': ['warn'],
    'import/order': [
      'warn',
      {
        groups: ['builtin', 'external', 'internal', ['parent', 'sibling', 'index']],
        'newlines-between': 'always',
        pathGroups: [
          {
            pattern: '@core/**',
            group: 'internal',
            position: 'after',
          },
        ],
        pathGroupsExcludedImportTypes: ['internal'],
      },
    ],
    'import/no-named-as-default-member': ['off'],
    'import/no-anonymous-default-export': [
      'error',
      {
        allowArray: false,
        allowArrowFunction: false,
        allowAnonymousClass: false,
        allowAnonymousFunction: false,
        allowCallExpression: true,
        allowNew: false,
        allowLiteral: false,
        allowObject: false,
      },
    ],
  },
  settings: {
    react: {
      version: 'detect',
    },
    'import/resolver': {
      typescript: {
        // @alwaysTryTypes always try to resolve types under `&amp;lt;root&amp;gt;@types`
        // directory even it doesn't contain any source code, like `@types/unist`
        alwaysTryTypes: true,
        project: './tsconfig.json',
        extensions: ['.ts', '.tsx'],
      },
    },
  },
}

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

&lt;/div&gt;



&lt;p&gt;We need to update &lt;strong&gt;.prettier.cjs&lt;/strong&gt; file as well:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = {
  semi: false,
  singleQuote: true,
  jsxSingleQuote: true,
  bracketSpacing: false,
  jsxBracketSameLine: false,
  arrowParens: 'avoid',
  useTabs: false,
  tabWidth: 2,
  printWidth: 100,
  trailingCommas: {
    array: true,
    object: true,
    function: false,
  },
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Import as a group is responsible for the below eslint rules:
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;'import/order': [&lt;br&gt;
      'warn',&lt;br&gt;
      {&lt;br&gt;
        groups: ['builtin', 'external', 'internal', ['parent', 'sibling', 'index']],&lt;br&gt;
        'newlines-between': 'always',&lt;br&gt;
        pathGroups: [&lt;br&gt;
          {&lt;br&gt;
            pattern: '@core/**',&lt;br&gt;
            group: 'internal',&lt;br&gt;
            position: 'after',&lt;br&gt;
          },&lt;br&gt;
        ],&lt;br&gt;
        pathGroupsExcludedImportTypes: ['internal'],&lt;br&gt;
      },&lt;br&gt;
 ],&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;here we need to specifics the group here which group i want. if your import group is not setup correctly this will show you warning into your console.&lt;/p&gt;

&lt;p&gt;We may check this reference from github: &lt;strong&gt;&lt;a href="https://github.com/khalid7487/study/tree/master/React/vites-config-eslint" rel="noopener noreferrer"&gt;https://github.com/khalid7487/study/tree/master/React/vites-config-eslint&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>eslint</category>
      <category>prettier</category>
      <category>gorupimport</category>
      <category>showeslintwarningintoconsole</category>
    </item>
    <item>
      <title>Matching search Text become small like google suggestions in Js</title>
      <dc:creator>Md. Khalid Hossen </dc:creator>
      <pubDate>Mon, 21 Nov 2022 15:04:52 +0000</pubDate>
      <link>https://dev.to/khalid7487/matching-search-text-become-small-like-google-suggestions-in-js-24ml</link>
      <guid>https://dev.to/khalid7487/matching-search-text-become-small-like-google-suggestions-in-js-24ml</guid>
      <description>&lt;p&gt;&lt;strong&gt;Making pain Text match data normal text and others become bold&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; let term = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,';
      let search1 = 'Lorem';
      let parts = term.split(search);
      console.log("parts", parts)
      return parts.map((item, i) =&amp;gt; (
        &amp;lt;&amp;gt;{item &amp;amp;&amp;amp; &amp;lt;strong&amp;gt;{item}&amp;lt;/strong&amp;gt;}{(i !== parts.length - 1) ? search1 : null}&amp;lt;/&amp;gt;
      ))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*&lt;em&gt;Array of Array match Make suggest text bold matching with search text *&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let termData = [
       { "title": "apple orange banana" },
       { "title": "upload app koro na kn???" },
        { "title": "range ban apple ana" },
        { "title": "Hello world" },
        { "title": "Hello no world" },
    ];
    let search = 'app';
    const matchData = termData?.filter((product) =&amp;gt; product.title.toLowerCase().includes(search.toLowerCase()));

    let newArray = [];

    matchData.map(item =&amp;gt; {
        return newArray.push(item.title.split(search))
    })

    return newArray.map((item, index) =&amp;gt; (
        &amp;lt;&amp;gt;
            {item.map((second, i) =&amp;gt; (
                &amp;lt;span onClick={() =&amp;gt; alert(`"hey MR.", ${index}`)}&amp;gt;{second &amp;amp;&amp;amp; &amp;lt;strong&amp;gt;{second}&amp;lt;/strong&amp;gt;}{(i !== item.length - 1) ? search : null}&amp;lt;/span&amp;gt;
            ))}
            &amp;lt;br /&amp;gt;
        &amp;lt;/&amp;gt;
    ))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>sql</category>
      <category>wordpress</category>
      <category>cybersecurity</category>
    </item>
  </channel>
</rss>
