<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Gokulnath P</title>
    <description>The latest articles on Forem by Gokulnath P (@gokulnathp).</description>
    <link>https://forem.com/gokulnathp</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%2F1036782%2Fffc619d2-caf5-4706-89df-a50a44cce41b.jpeg</url>
      <title>Forem: Gokulnath P</title>
      <link>https://forem.com/gokulnathp</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/gokulnathp"/>
    <language>en</language>
    <item>
      <title>Kafka Essentials: Building Scalable and Reliable Event Streaming</title>
      <dc:creator>Gokulnath P</dc:creator>
      <pubDate>Mon, 13 Oct 2025 15:21:46 +0000</pubDate>
      <link>https://forem.com/gokulnathp/kafka-essentials-building-scalable-and-reliable-event-streaming-3pn7</link>
      <guid>https://forem.com/gokulnathp/kafka-essentials-building-scalable-and-reliable-event-streaming-3pn7</guid>
      <description>&lt;p&gt;In our previous blog, we covered the basic building blocks like producers, consumers, and topics that help send messages from one service to another. To build a truly scalable app, we need to go beyond these basics. Let’s look at some other Kafka concepts that help us make communication production-ready.&lt;/p&gt;

&lt;h2&gt;
  
  
  Partitions
&lt;/h2&gt;

&lt;p&gt;Imagine a topic in Kafka like a big folder where all messages about the same thing go. Now picture 1000 orders coming in at once — all those order messages go into this folder. The problem is, they get handled one by one, like people standing in a single line. That can be slow when there are lots of orders.&lt;/p&gt;

&lt;p&gt;Partitions fix this by splitting the big folder into smaller pieces called partitions. Think of partitions like separate checkout lines at a grocery store — multiple lines help more people check out quickly.&lt;/p&gt;

&lt;p&gt;Kafka makes sure messages stay in order within each partition, because sometimes order really matters. But messages in different partitions don’t have to be in order.&lt;/p&gt;

&lt;p&gt;So partitions help Kafka work on many messages at the same time, speeding things up and making them smoother.&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%2F5gtdszr9ozpvf2eypm14.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%2F5gtdszr9ozpvf2eypm14.png" alt="Kafka Partition" width="800" height="526"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Message Key
&lt;/h2&gt;

&lt;p&gt;Keys play an important role in deciding which partition a message goes to. Kafka uses the key to figure this out by running it through a process called hashing (think of it like a recipe that always gives the same result for the same key). This makes sure all messages with the same key end up in the same partition.&lt;/p&gt;

&lt;p&gt;If a message doesn’t have a key, Kafka spreads those messages evenly across different partitions, like taking turns, to keep things balanced.&lt;/p&gt;

&lt;p&gt;Using keys lets us group related messages together in one partition. For example, all events related to a single user will always go to the same partition, so they stay in order.&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%2Fdl76er7tc0a2libcu0go.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%2Fdl76er7tc0a2libcu0go.png" alt="Kafka Message Key" width="800" height="527"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Consumer Group
&lt;/h2&gt;

&lt;p&gt;Partitions let us split events into multiple streams so consumers can read them faster. But what if you have two partitions and two consumers? How do we make sure each consumer reads different partitions without both reading the same messages?&lt;/p&gt;

&lt;p&gt;That’s where consumer groups come in. You can create multiple consumers that share the same group ID. Kafka then assigns partitions to each consumer in the group, making sure each partition is read by only one consumer. This way, consumers work in parallel without duplicate messages.&lt;/p&gt;

&lt;p&gt;So, consumer groups help spread the work and make event processing faster and more efficient.&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%2F7wmqsbsw69m26dqiszze.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%2F7wmqsbsw69m26dqiszze.png" alt="Kafka Consumer Group with less consumers" width="800" height="526"&gt;&lt;/a&gt;&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%2Ffgas5e0e8p9xeay3dzhm.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%2Ffgas5e0e8p9xeay3dzhm.png" alt="Kafka Consumer Group with equal consumers" width="800" height="527"&gt;&lt;/a&gt;&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%2Fqd7uam602no0jng63bbf.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%2Fqd7uam602no0jng63bbf.png" alt="Kafka Consumer Group with more consumers" width="800" height="526"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Offset
&lt;/h2&gt;

&lt;p&gt;How do consumers know which message to read next? And if they stop for a while, how do other consumers in the group know where to continue?&lt;/p&gt;

&lt;p&gt;That’s where offsets come in. Every message in a partition gets a unique number called an offset — it’s like a simple count starting at 0. Kafka keeps track of offsets separately for each partition to make sure messages stay in the right order.&lt;/p&gt;

&lt;p&gt;Consumers “commit” their current offset to Kafka to remember which messages they’ve read. This way, if they stop or another consumer takes over, they know exactly where to pick up without missing or repeating messages.&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%2Fjcmlahxfrfc3hgvrq6lq.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%2Fjcmlahxfrfc3hgvrq6lq.png" alt="Kafka Offset" width="800" height="526"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Replication
&lt;/h2&gt;

&lt;p&gt;We know a Kafka cluster has multiple brokers so if one broker goes down, others can keep things running. But how do those other brokers get the events they need to continue without missing anything?&lt;/p&gt;

&lt;p&gt;That’s where replication comes in. Kafka makes copies of each partition and stores them on different brokers in the cluster. This means if one broker fails, the data is still safe and available from the other brokers.&lt;/p&gt;

&lt;p&gt;When you create a topic, you decide the replication factor — basically how many copies of each partition you want. The more copies, the safer your data is.&lt;/p&gt;

&lt;p&gt;A few other things to remember:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The replication factor can’t be bigger than how many brokers you have, because each copy lives on its own broker.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Every partition has a “leader” broker responsible for handling all reads and writes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the leader broker crashes, Kafka automatically switches leadership to another broker that has a copy—making sure your data stream never misses a beat.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&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%2Futrmdg3uqk791jw22llj.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%2Futrmdg3uqk791jw22llj.png" alt="Kafka Replication with equal brokers" width="800" height="526"&gt;&lt;/a&gt;&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%2Fs5ru5cichw5a0kdbm4fe.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%2Fs5ru5cichw5a0kdbm4fe.png" alt="Kafka Replication with more brokers" width="800" height="526"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Together, these concepts form the core of Kafka’s ability to handle large-scale event streaming, making sure your app can process messages quickly, reliably, and without losing data.&lt;/p&gt;

&lt;p&gt;Ready to see these ideas in action? Keep an eye out for our next blog where we roll up our sleeves and get hands-on with Kafka!&lt;/p&gt;

</description>
      <category>kafka</category>
      <category>eventdriven</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Kafka Fundamentals: A quick look at the basic building blocks</title>
      <dc:creator>Gokulnath P</dc:creator>
      <pubDate>Mon, 13 Oct 2025 15:07:44 +0000</pubDate>
      <link>https://forem.com/gokulnathp/kafka-fundamentals-a-quick-look-at-the-basic-building-blocks-1cla</link>
      <guid>https://forem.com/gokulnathp/kafka-fundamentals-a-quick-look-at-the-basic-building-blocks-1cla</guid>
      <description>&lt;p&gt;So what’s Kafka, anyway? Kafka is a super-fast, reliable tool for moving messages (events) between apps and services. Instead of sending data directly (like a phone call), services share what’s happening through Kafka — almost like posting messages on a community board. Others can check those messages whenever they want.&lt;/p&gt;

&lt;p&gt;This setup lets lots of microservices talk with each other in a flexible, reliable way — making your app easier to build and scale without all the tight connections that can cause problems.&lt;/p&gt;

&lt;p&gt;Let’s start by breaking down each building block of Kafka to see how they help everything communicate behind the scenes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Messages / Events
&lt;/h2&gt;

&lt;p&gt;Messages, sometimes called events, are like little notes that one service sends to another. They carry data, along with some extra info like when the message was created. They also have something called keys — we’ll explain how keys help group messages later. The important thing is that once a message is sent, it can’t be changed — just like sending a letter in the mail. This helps keep a clear and reliable record of what happened.&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%2Fkvqi6xr0y27fmuc9sfp6.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%2Fkvqi6xr0y27fmuc9sfp6.png" alt="Kafka Message" width="800" height="527"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Topic
&lt;/h2&gt;

&lt;p&gt;Think of a topic like a folder that groups together similar events. Producers send their messages to a topic, and consumers subscribe to the topics they care about to get those events.&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%2Fdp4q4lizqmv82u151eox.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%2Fdp4q4lizqmv82u151eox.png" alt="Kafka Topic" width="800" height="527"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Broker
&lt;/h2&gt;

&lt;p&gt;A broker is a server that manages the event streaming behind the scenes. It’s responsible for receiving messages, storing them safely, and then sending them to other services when they ask for them.&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%2Fv0x6zti4oc3zlhcedeci.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%2Fv0x6zti4oc3zlhcedeci.png" alt="Kafka Broker" width="800" height="527"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Cluster
&lt;/h2&gt;

&lt;p&gt;A Kafka cluster is created by running multiple brokers together. The idea is that if one broker stops working, the others can keep everything running without any problems, so the event streaming never stops.&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%2Ffstqysasbewbq9akoz0x.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%2Ffstqysasbewbq9akoz0x.png" alt="Kafka Cluster" width="800" height="526"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Producer
&lt;/h2&gt;

&lt;p&gt;A producer is an app or client that sends messages. It connects to the Kafka cluster and sends its messages to a specific topic.&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%2Ftn32ohho4g0sq1nuj7vn.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%2Ftn32ohho4g0sq1nuj7vn.png" alt="Kafka Producer" width="800" height="527"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Consumer
&lt;/h2&gt;

&lt;p&gt;A consumer is an app or client that reads messages. It subscribes to one or more topics and pulls messages from the Kafka cluster to process or use them.&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%2Fhuhl93d07en2yjza5j3b.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%2Fhuhl93d07en2yjza5j3b.png" alt="Kafka Consumer" width="800" height="526"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Together, these building blocks form the heart of Kafka’s messaging system, letting different parts of your application communicate smoothly and reliably.&lt;/p&gt;

&lt;p&gt;In future blogs, we’ll dive deeper into Kafka topics like partitions, consumer groups, offsets, and replication to get the full picture of how Kafka works in production. This way, you’ll build a strong foundation and be ready to use Kafka effectively in your own projects.&lt;/p&gt;

</description>
      <category>kafka</category>
      <category>eventdriven</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Kafka for beginners: An event streaming platform</title>
      <dc:creator>Gokulnath P</dc:creator>
      <pubDate>Mon, 13 Oct 2025 14:13:30 +0000</pubDate>
      <link>https://forem.com/gokulnathp/kafka-for-beginners-oc2</link>
      <guid>https://forem.com/gokulnathp/kafka-for-beginners-oc2</guid>
      <description>&lt;p&gt;Have you ever wondered how big apps handle millions of messages every second without slowing down or crashing? As digital platforms keep changing, so does our code. To build apps that can grow smoothly, we break down a big app into smaller, independent parts called microservices — each doing its own job.&lt;/p&gt;

&lt;p&gt;One big question when building apps with lots of these microservices is: how do they talk to each other?&lt;/p&gt;

&lt;p&gt;The usual way, using REST APIs, can make these parts too tightly connected. That means if you change one, it might accidentally break others — not good for growing or fixing your app.&lt;/p&gt;

&lt;p&gt;This is where event streaming comes in. Think of it as services sending out messages about what they’ve done, and other services listening if they’re interested. This keeps everything more flexible and easier to manage.&lt;/p&gt;

&lt;p&gt;By the end of this blog series, you’ll understand how Kafka, a popular event streaming tool, helps these chatting services work smoothly together.&lt;/p&gt;

</description>
      <category>kafka</category>
      <category>eventdriven</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>React: Effective UI State Management Practices</title>
      <dc:creator>Gokulnath P</dc:creator>
      <pubDate>Mon, 06 Oct 2025 15:01:38 +0000</pubDate>
      <link>https://forem.com/gokulnathp/react-effective-ui-practices-3h82</link>
      <guid>https://forem.com/gokulnathp/react-effective-ui-practices-3h82</guid>
      <description>&lt;p&gt;As web development evolves, it is important to choose the right practices that help us create a scalable, readable, maintainable, and testable codebase. In this blog series, we will look at different practices that help us create such a codebase.&lt;/p&gt;

&lt;p&gt;This blog series is divided into three topics:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Application Design&lt;/li&gt;
&lt;li&gt;State Management&lt;/li&gt;
&lt;li&gt;Testing Practices&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  State Management
&lt;/h2&gt;

&lt;p&gt;Bridging the gap between business goals and React implementation requires thoughtful state design. In today's blog, we will be exploring the following practices under State Management:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Understanding the state&lt;/li&gt;
&lt;li&gt;Efficiently managing the form state&lt;/li&gt;
&lt;li&gt;You Might Not Need a useEffect&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Understanding the state
&lt;/h3&gt;

&lt;p&gt;To build performance-heavy applications, it is important to understand the scope of state and what should go into it. State should be placed as close as possible to the components that require the data, to avoid unnecessary re-rendering. Identify what doesn't qualify as state&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Does it &lt;strong&gt;remain unchanged&lt;/strong&gt; over time? If yes, it isn’t state.&lt;/li&gt;
&lt;li&gt;Is it &lt;strong&gt;passed in from a parent&lt;/strong&gt; via props? If yes, it isn’t state.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Can you compute it&lt;/strong&gt; based on existing state or props in your component? If yes, it definitely isn’t state.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Reference:&lt;/strong&gt; &lt;a href="https://react.dev/learn/thinking-in-react#step-3-find-the-minimal-but-complete-representation-of-ui-state" rel="noopener noreferrer"&gt;Find the minimal but complete representation of UI state&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Efficiently Managing Form State
&lt;/h3&gt;

&lt;p&gt;Maintaining the state of forms is as important as managing application-level state. Forms have unique needs such as handling frequent changes, applying validation, and processing submissions. Since form state changes frequently, place it close to the form component to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Improve application performance by avoiding unnecessary re-rendering of other components.&lt;/li&gt;
&lt;li&gt;Test the behaviour of the form, not its internal implementation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  You Might Not Need a useEffect
&lt;/h3&gt;

&lt;p&gt;useEffect is an escape hatch in React, allowing interaction with external systems such as non-React widgets, network calls, or the browser DOM. Avoid using useEffect just to update a component’s state from prop or state changes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You don’t need Effects to transform data for rendering.&lt;/li&gt;
&lt;li&gt;You don’t need Effects to handle user events.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Reference:&lt;/strong&gt; &lt;a href="https://react.dev/learn/you-might-not-need-an-effect" rel="noopener noreferrer"&gt;You Might Not Need an Effect&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s all for today. In the next blog, we’ll explore best practices for testing React applications.&lt;/p&gt;

</description>
      <category>reactjsdevelopment</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>React: Effective UI Application Design Practices</title>
      <dc:creator>Gokulnath P</dc:creator>
      <pubDate>Wed, 22 May 2024 03:25:34 +0000</pubDate>
      <link>https://forem.com/gokulnathp/react-effective-ui-practices-478o</link>
      <guid>https://forem.com/gokulnathp/react-effective-ui-practices-478o</guid>
      <description>&lt;p&gt;As web development evolves, it is important to choose the right practices that help us create a scalable, readable, maintainable, and testable codebase. In this blog series, we will look at different practices that help us create such a codebase.&lt;/p&gt;

&lt;p&gt;This blog series is divided into three topics:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Application Design&lt;/li&gt;
&lt;li&gt;State Management&lt;/li&gt;
&lt;li&gt;Testing Practices&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Application Design
&lt;/h2&gt;

&lt;p&gt;Understanding how to convert business requirements into a React codebase with minimal effort is crucial. In today's blog, we will be exploring the following practices under Application Design:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Extracting Design Components&lt;/li&gt;
&lt;li&gt;Building Application Logic as Custom Hooks&lt;/li&gt;
&lt;li&gt;Embracing Component Architecture&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Extracting Design Components
&lt;/h3&gt;

&lt;p&gt;UI applications are nothing but a composition of design components such as buttons, tables, and accordions. These design components can be as granular as a button, icon, or form row, or as large as a table, accordion, or form. It is important to decouple these design components from business logic so that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We can reuse them across all places without redesigning them every time.&lt;/li&gt;
&lt;li&gt;Design changes can be applied in a single place and reflect everywhere.&lt;/li&gt;
&lt;li&gt;We can test the behaviour of these design components in an isolated environment since they are decoupled from business logic.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Building Application Logic as Custom Hooks
&lt;/h3&gt;

&lt;p&gt;React Hooks are not just another feature; they represent a paradigm shift in the React development journey. By embracing React Hooks, developers can focus more on building the application logic rather than grappling with React’s complexities. This shift orchestrates:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Efficient code organisation, which helps improve the reusability and maintainability of behaviours.&lt;/li&gt;
&lt;li&gt;Easier testing.&lt;/li&gt;
&lt;li&gt;Improved overall application performance by avoiding unnecessary re-renders.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Reference:&lt;/strong&gt; &lt;a href="https://react.dev/learn/reusing-logic-with-custom-hooks" rel="noopener noreferrer"&gt;Reusing Logic with Custom Hooks&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Embracing Component Architecture
&lt;/h3&gt;

&lt;p&gt;Component architecture is a fundamental concept in React development. Breaking our application into smaller components instead of having one bulk component is as important as extracting design components and behaviours. As the complexity of a component increases, it is a good idea to split it into separate components to make your code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;More readable and maintainable.&lt;/li&gt;
&lt;li&gt;Easier to test.&lt;/li&gt;
&lt;li&gt;Loosely coupled with other behaviours and components.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Reference:&lt;/strong&gt; &lt;a href="https://react.dev/learn/thinking-in-react#step-1-break-the-ui-into-a-component-hierarchy" rel="noopener noreferrer"&gt;Break the UI into a component hierarchy&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That is all for today. In our next blog, we will look at some of the best practices for managing and designing state in React.&lt;/p&gt;

</description>
      <category>reactjsdevelopment</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Boost Your Productivity with a Node JS Code Generator</title>
      <dc:creator>Gokulnath P</dc:creator>
      <pubDate>Mon, 06 Mar 2023 09:37:55 +0000</pubDate>
      <link>https://forem.com/gokulnathp/boost-your-productivity-with-a-node-js-code-generator-51mk</link>
      <guid>https://forem.com/gokulnathp/boost-your-productivity-with-a-node-js-code-generator-51mk</guid>
      <description>&lt;p&gt;A code generator is a tool that automates the process of creating code. It can save you a lot of time and effort, especially if you need to create similar code repeatedly. Rather than writing the same code over and over again, you can use a code generator to create templates that you can reuse for different projects.&lt;/p&gt;

&lt;p&gt;Using a code generator can also help you to maintain consistency across your projects. You can define coding standards and conventions in your code generator, and then use it to generate code that adheres to these standards. This can help to ensure that your code is more reliable, easier to maintain, and less prone to errors.&lt;/p&gt;

&lt;p&gt;Another benefit of using a code generator is that it can reduce the amount of manual work involved in the coding process. By automating repetitive tasks, you can free up your time to focus on more complex and challenging tasks that require your attention.&lt;/p&gt;

&lt;p&gt;Overall, a code generator can be a powerful tool for developers who want to save time, improve code quality, and reduce errors in their projects. With a code generator, you can create code faster, more consistently, and with less effort.&lt;/p&gt;

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

&lt;p&gt;Before we get started, you'll need to have NPM installed on your computer. If you don't have NPM installed, you can download it from the &lt;a href="https://nodejs.org/en/download/"&gt;official website&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Contents
&lt;/h2&gt;

&lt;p&gt;In this post, we will cover the following topics:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How to create a NPM package&lt;/li&gt;
&lt;li&gt;How to create Command-Line Interface (CLI) application in NPM&lt;/li&gt;
&lt;li&gt;How to create a generator using the "&lt;a href="https://www.npmjs.com/package/fs-extra"&gt;fs-extra&lt;/a&gt;", "&lt;a href="https://www.npmjs.com/package/enquirer"&gt;enquirer&lt;/a&gt;", and "&lt;a href="https://www.npmjs.com/package/replace-in-file"&gt;replace-in-file&lt;/a&gt;" modules&lt;/li&gt;
&lt;li&gt;Using the generator to create a custom web application&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Each section will provide a step-by-step guide to help you create your own code generator and customise it to your needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Creating a NPM Package: A Step-by-Step Guide
&lt;/h2&gt;

&lt;p&gt;Creating an NPM package is a simple and straightforward process that allows you to share your code with others or use it in other projects. In this example, we'll walk you through how to create an NPM package that exports a simple greeting function.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Create the Package Directory
&lt;/h3&gt;

&lt;p&gt;First, we need to create a new directory for our package. In our example, we'll call it "custom-package". Inside this directory, we'll create two files: index.js and package.json.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;custom-package
&lt;span class="nb"&gt;cd &lt;/span&gt;custom-package
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Create the index.js File
&lt;/h3&gt;

&lt;p&gt;In the index.js file, we'll export a function that will output a greeting to the console.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;greet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Welcome to the exciting world of creating your own NPM packages!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;greet&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Create the package.json File
&lt;/h3&gt;

&lt;p&gt;In the package.json file, we'll include metadata about our package such as its name, version, and main entry point.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"custom-package"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1.0.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"main"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"index.js"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4: Link the Package Locally
&lt;/h3&gt;

&lt;p&gt;Before we can use our package in another project, we need to link it locally using the "npm link" command.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 5: Create the Consumer Directory
&lt;/h3&gt;

&lt;p&gt;Next, we need to create a new directory for our consumer project. In our example, we'll call it "consumer". Inside this directory, we'll create two files: index.js and package.json.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ..
&lt;span class="nb"&gt;mkdir &lt;/span&gt;consumer
&lt;span class="nb"&gt;cd &lt;/span&gt;consumer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 6: Install the Package
&lt;/h3&gt;

&lt;p&gt;Now that we have our package linked locally, we can install it in our consumer project using the "npm link" command with the name of our package.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;link &lt;/span&gt;custom-package
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 7: Use the Package
&lt;/h3&gt;

&lt;p&gt;In the index.js file of our consumer project, we'll require the "custom-package" package and call its greet function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;greet&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;custom-package&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 8: Run the Consumer Project
&lt;/h3&gt;

&lt;p&gt;Finally, we can run the consumer project using the "npm start" command, which will execute the index.js file and output the greeting from our "custom-package" package.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"consumer"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1.0.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"node index.js"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's it! We've successfully created an NPM package and used it in a consumer project. This is just the beginning of what you can do with NPM packages, so feel free to experiment and explore all the possibilities.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Creating a Command-Line Interface (CLI) Application in NPM: A Step-by-Step Guide
&lt;/h2&gt;

&lt;p&gt;Welcome to the world of creating command-line interface (CLI) applications in NPM! In this section, we will walk through the steps to create a simple CLI application that prints a welcome message to the console.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Create the Package Directory
&lt;/h3&gt;

&lt;p&gt;First, we need to create a new directory for our package. In our example, we'll call it "npm-cli". Inside this directory, we'll create two files: index.js and package.json.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;npm-cli
&lt;span class="nb"&gt;cd &lt;/span&gt;npm-cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Create the index.js File
&lt;/h3&gt;

&lt;p&gt;In the index.js file, we will print a welcome message to the console when the CLI is run..&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cp"&gt;#!/usr/bin/env node
&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Welcome to the world of creating command-line interface (CLI) applications in NPM!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first line (&lt;code&gt;#!/usr/bin/env node&lt;/code&gt;) tells your terminal that this file should be executed using Node.js.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Create the package.json File
&lt;/h3&gt;

&lt;p&gt;In the package.json file, we'll include metadata about our package such as its name, version and bin (path and command for executables).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"npm-cli"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1.0.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"bin"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"npm-cli"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"index.js"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tells NPM that your package has a &lt;code&gt;bin&lt;/code&gt; executable called &lt;code&gt;npm-cli&lt;/code&gt;, which should be linked to the &lt;code&gt;index.js&lt;/code&gt; file you created in the previous step.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Link the Package Locally
&lt;/h3&gt;

&lt;p&gt;Before we can use our package, we need to link it locally using the "npm link" command.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;This will create a symbolic link from your package directory to your global NPM directory.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: Use the Package
&lt;/h3&gt;

&lt;p&gt;Finally, we can run "npm-cli" command in terminal, which will execute the index.js file and output the welcome message.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;That's it! You've created a simple NPM CLI. Now you can modify the index.js file to add more functionality to your CLI.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Creating a Custom Generator with Node js: A Step-by-Step Guide
&lt;/h2&gt;

&lt;p&gt;In this section, we will walk through the steps to create a simple code generator that will bootstrap a project from existing template.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Create a New Directory
&lt;/h3&gt;

&lt;p&gt;Create a new directory named "create-custom-webapp" and navigate into it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;create-custom-webapp
&lt;span class="nb"&gt;cd &lt;/span&gt;create-custom-webapp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Create a package.json File
&lt;/h3&gt;

&lt;p&gt;This file will contain information about our custom generator, including its name, version, description, and dependencies. Here's what the "package.json" file should look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"create-custom-webapp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1.0.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"A tool to generate custom webapp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"bin"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"create-custom-webapp"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"cli.js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"ccw"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"cli.js"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"dependencies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"commander"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"10.0.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"enquirer"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2.3.6"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"fs-extra"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"11.1.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"replace-in-file"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"6.3.5"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that we have included the "bin" field in our "package.json" file, which tells NPM that our custom generator will have two command line interfaces ("create-custom-webapp" and "ccw") that will be executed by running the "cli.js" file.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Create the Command-Line Interface (CLI)
&lt;/h3&gt;

&lt;p&gt;Create a new file named &lt;code&gt;cli.js&lt;/code&gt; in the root of the project and add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cp"&gt;#!/usr/bin/env node
&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Command&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;commander&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;packageJson&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./package.json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;prompt&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;enquirer&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;bootstrap&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;readUserInput&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;input&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;appName&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;What is your application name?&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;program&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Command&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;program&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;packageJson&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;version&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;packageJson&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;version&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;description&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;packageJson&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;description&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;readUserInput&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bootstrap&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="nx"&gt;program&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code sets up the "&lt;a href="https://www.npmjs.com/package/commander"&gt;commander&lt;/a&gt;" package to handle the command-line interface for your generator. The &lt;code&gt;readUserInput&lt;/code&gt; function uses the "&lt;a href="https://www.npmjs.com/package/enquirer"&gt;enquirer&lt;/a&gt;" package to prompt the user for input, and the &lt;code&gt;bootstrap&lt;/code&gt; function (which we will define in the next step) is called to generate the project with the user's input.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Define the &lt;code&gt;bootstrap&lt;/code&gt; Function
&lt;/h3&gt;

&lt;p&gt;Create a new directory named &lt;code&gt;src&lt;/code&gt; and a file named &lt;code&gt;index.js&lt;/code&gt; inside the &lt;code&gt;src&lt;/code&gt; directory. Add the following code to &lt;code&gt;index.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;fs-extra&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;path&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;execSync&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;child_process&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;replaceInFile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;replace-in-file&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="cm"&gt;/**
 * A function to bootstrap a project from template.
 * @param {Object} config - The config object.
 * @param {string} config.appName - The name of the application.
 */&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bootstrap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;templatePath&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;..&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;templates&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;destinationPath&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cwd&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;appName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Bootstrapping simple React web app&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;copySync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;templatePath&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;destinationPath&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Customizing a app with information provided by user&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;replaceInFile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sync&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;files&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;destinationPath&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;**&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;*&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="na"&gt;from&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;CGD_APP_NAME&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;appName&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Installing required dependencies to start the application&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;execSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;npm i&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;cwd&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;destinationPath&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Inorder to run an application, navigate to &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;appName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; folder and run 'npm start'`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;bootstrap&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;bootstrap&lt;/code&gt; function takes a configuration object as input that includes the &lt;code&gt;appName&lt;/code&gt; property, which is the name of the application to be generated. The function first sets up paths for the source and destination folders using the Node JS "&lt;a href="https://nodejs.org/api/path.html"&gt;path&lt;/a&gt;" module. Then, it copies the contents of the &lt;code&gt;templates&lt;/code&gt; directory (which contains a basic React web app) to a new directory with the name specified by the user.&lt;/p&gt;

&lt;p&gt;After copying the template files, the function uses the "&lt;a href="https://www.npmjs.com/package/replace-in-file"&gt;replace-in-file&lt;/a&gt;" package to replace all instances of the placeholder string "CGD_APP_NAME" with the actual &lt;code&gt;appName&lt;/code&gt; provided by the user. This ensures that the name of the application is correctly reflected in all files.&lt;/p&gt;

&lt;p&gt;Finally, the function uses the "&lt;a href="https://nodejs.org/api/child_process.html"&gt;child_process&lt;/a&gt;" module to execute the command &lt;code&gt;npm install&lt;/code&gt; in the new directory, which installs all necessary dependencies for the generated application. Once the dependencies are installed, the function logs a message to the console to inform the user how to start the application.&lt;/p&gt;

&lt;p&gt;That's it! With this &lt;code&gt;bootstrap&lt;/code&gt; function, our custom generator can now generate a basic React web app with the user-specified name and all required dependencies installed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: Create the Template Files
&lt;/h3&gt;

&lt;p&gt;Create a new directory names &lt;code&gt;templates&lt;/code&gt; and copy the file from &lt;a href="https://github.com/GokulnathP/code-generator/tree/main/create-custom-webapp/templates"&gt;here&lt;/a&gt; into the &lt;code&gt;templates&lt;/code&gt; folder.&lt;/p&gt;

&lt;p&gt;This folder contains the files that will be used to generate the web application. The folder structure and files inside the &lt;code&gt;templates&lt;/code&gt; folder are based on the type of application we want to generate. In this case, we're generating a simple web application using &lt;a href="https://reactjs.org/"&gt;React&lt;/a&gt; and &lt;a href="https://webpack.js.org/"&gt;Webpack&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The folder structure is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;templates/
  |- public/
  |   |- index.html
  |- src/
  |   |- index.js
  |- package.json
  |- webpack.config.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's take a closer look at each of these files and folders:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;public/&lt;/code&gt;: This folder contains the static assets that will be served by the application. In our case, it contains an &lt;code&gt;index.html&lt;/code&gt; file.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;src/&lt;/code&gt;: This folder contains the source code of the application. It contains an &lt;code&gt;index.js&lt;/code&gt; file, which is the entry point for our application.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;package.json&lt;/code&gt;: This file contains the metadata and dependencies for the application. It specifies the dependencies required to run our application, including React and Webpack.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;webpack.config.js&lt;/code&gt;: This file contains the configuration for Webpack. It specifies the entry point for our application, the output directory for the compiled assets, and the loaders and plugins required to compile the application code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When the user generates a new web application using our custom generator, these files will be copied to the new project directory with any necessary modifications based on the user's input.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 6: Link the Package Locally
&lt;/h3&gt;

&lt;p&gt;In the &lt;code&gt;create-custom-webapp&lt;/code&gt; directory, run the following command to link the package to the global module directory&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 7: Use the Package
&lt;/h3&gt;

&lt;p&gt;Navigate to the directory where you want to create your new project and run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;create-custom-webapp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will start the custom generator and prompt you to enter a name for your application. Once the details are entered it will generate a project and will do install dependencies inside it.&lt;/p&gt;

&lt;p&gt;To start your application, navigate to the new directory and run the following command:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Congratulations, you have successfully created a custom generator to create a new web application from a template!&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;In conclusion, code generators, such as the one we built in this tutorial, can save you time and effort by automating repetitive tasks and providing a starting point for your projects. By creating an npm package with a CLI, we were able to create a custom generator that asks for user input and generates a customized application with the necessary dependencies. By leveraging the "fs-extra", "commander", "enquirer", and "replace-in-file" modules, we were able to make the generator easy to use and customizable for different projects.&lt;/p&gt;

&lt;p&gt;We hope this tutorial has been helpful in showing you how to create your own custom generator. With these tools, you can easily create new applications and get started on your next project with minimal effort. Happy coding!&lt;/p&gt;

&lt;p&gt;You can find the code snippets used in this blog &lt;a href="https://github.com/GokulnathP/code-generator"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>node</category>
      <category>npm</category>
    </item>
  </channel>
</rss>
