<?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: Harshit Goyal</title>
    <description>The latest articles on DEV Community by Harshit Goyal (@harsh_goyal).</description>
    <link>https://dev.to/harsh_goyal</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%2F3191946%2F1acdd251-b305-4478-b00b-d3697fea5d04.png</url>
      <title>DEV Community: Harshit Goyal</title>
      <link>https://dev.to/harsh_goyal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/harsh_goyal"/>
    <language>en</language>
    <item>
      <title>Docker Basics: What Every New Developer Should Know</title>
      <dc:creator>Harshit Goyal</dc:creator>
      <pubDate>Tue, 27 May 2025 18:52:09 +0000</pubDate>
      <link>https://dev.to/harsh_goyal/docker-for-beginners-477c</link>
      <guid>https://dev.to/harsh_goyal/docker-for-beginners-477c</guid>
      <description>&lt;p&gt;Docker containers are really useful and often misunderstood, so in this article we will explore what docker is and how it could be used in a dev workflow.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Docker
&lt;/h2&gt;

&lt;p&gt;Docker is a platform that allows you to build, run, and manage applications in lightweight, portable containers.&lt;br&gt;
Each container has it own virtual file system.&lt;/p&gt;

&lt;p&gt;The docker containers run in an isolated environment, so there are no version conflicts.&lt;/p&gt;

&lt;p&gt;Consider a developer working on an application that uses Redis and MongoDB. To get started, they would typically need to install both services on their local machine. If they later need to switch to a different version of MongoDB, they would have to download and install that version separately. Managing multiple versions or running them side by side can become complex and cumbersome.&lt;/p&gt;

&lt;p&gt;With docker he can simplify his process of development as he can run these applications on docker in isolated containers. &lt;br&gt;
We will see in the later part of this tutorial, how we can run multiple applications together with docker.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Please install docker locally to follow along&lt;br&gt;
Docker installtion varies according to the OS , check on official &lt;a href="https://docs.docker.com/desktop/" rel="noopener noreferrer"&gt;docker website&lt;/a&gt; for details.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;h2&gt;
  
  
  Docker basic commands
&lt;/h2&gt;

&lt;p&gt;To check if docker is correctly installed on your system, try -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run hello-world
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your output should be like this&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%2F77lailgin1xb5heopdxd.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%2F77lailgin1xb5heopdxd.png" alt="Docker-hello-world" width="800" height="524"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now docker is correctly installed on your system , lets explore some basic docker commands -&lt;/p&gt;

&lt;p&gt;1.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;This command will list all docker images in your local system.&lt;/p&gt;

&lt;p&gt;2.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker pull mongo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will pull the image from a docker image repository.&lt;br&gt;
By default it uses &lt;a href="https://hub.docker.com/" rel="noopener noreferrer"&gt;dockerHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Every image has two fields-&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Image name&lt;/li&gt;
&lt;li&gt;Version&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In our case when we use mongo, mongo is image name and by default version is latest.&lt;br&gt;
So the command is same as -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker pull mongo:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of latest, we can specify the exact version we require.&lt;/p&gt;

&lt;p&gt;3.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run mongo:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will start the container.&lt;br&gt;
Now when we start the container, we need to access the port of the docker container.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -p 27017:27017 mongo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The first port is the host port &lt;/li&gt;
&lt;li&gt;Second port is container port&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;27017 is the default port mongoDb exposes, so we open the same port on our local.&lt;br&gt;
Now, whenever we setup a database, we need an admin username and password.&lt;br&gt;
Its similar for docker as well.&lt;br&gt;
For mongo we can provide environment variables to set these fields.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -d \
  --name my-mongo \
  -e MONGO_INITDB_ROOT_USERNAME=admin \
  -e MONGO_INITDB_ROOT_PASSWORD=secretpassword \
  -p 27017:27017 \
  mongo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now mongoDb is all setup and available on port 27017.&lt;/p&gt;

&lt;p&gt;4.&lt;br&gt;
We can also specify volumes to persist the data.&lt;br&gt;
Normally, if we stop a docker container, we loose the data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -v redisdata:/data redis
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will persist all the cached data.&lt;/p&gt;




&lt;h2&gt;
  
  
  Docker Compose
&lt;/h2&gt;

&lt;p&gt;Now that we have our MongoDB container set up, we still need a GUI to visualize the data, along with Redis. While it's possible to set up separate containers for each service manually, doing so requires considerable effort—starting each one individually and repeating the setup steps every time we need them can be time-consuming and inefficient.&lt;/p&gt;

&lt;p&gt;To ease this process, we have docker compose.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Docker Compose is a tool that helps you define and run multi-container Docker applications using a simple YAML file.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We can create a docker-compose.yml file in the root directory.&lt;br&gt;
The Compose file also requires the same configuration settings that we used when initially starting the MongoDB container.&lt;/p&gt;

&lt;p&gt;Here is an example of docker compose file -&lt;br&gt;
&lt;/p&gt;

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

services:
  mongo-db:
    image: mongo
    ports:
      - 27017:27017
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: password
    volumes:
      - mongo-data:/data/db

  mongo-express:
    image: mongo-express
    ports:
      - 8081:8081
    environment:
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: password
      ME_CONFIG_MONGODB_SERVER: mongo-db
    depends_on:
      - mongo-db

  redis:
    image: redis
    ports:
      - 6379:6379
    volumes:
      - redis-data:/data

# use volumes to persist data
volumes:
  mongo-data:
  redis-data:

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

&lt;/div&gt;



&lt;p&gt;To run we can use -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker-compose up -d
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will start 3 containers - mongoDb, mongo-express (GUI for mongo) and redis.&lt;br&gt;
Now with a single command we can spin up any number of containers which are configured in docker compose file.&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%2Ffw4h7sfjuxlwm36u9sf8.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%2Ffw4h7sfjuxlwm36u9sf8.png" alt="Docker-desktop-compose-up" width="800" height="132"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you finish the development, you can use -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker-compose down
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will stop all the containers (running from docker compose).&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%2Fxsszhiz9l9cwnjy30ifo.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%2Fxsszhiz9l9cwnjy30ifo.png" alt="Docker-compose-down" width="800" height="80"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Let me know in comments if you would like an advanced use case tutorial.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Using elastic search to optimize text search 🔍</title>
      <dc:creator>Harshit Goyal</dc:creator>
      <pubDate>Wed, 21 May 2025 16:06:45 +0000</pubDate>
      <link>https://dev.to/harsh_goyal/using-elastic-search-to-optimize-text-search-3nm6</link>
      <guid>https://dev.to/harsh_goyal/using-elastic-search-to-optimize-text-search-3nm6</guid>
      <description>&lt;p&gt;Text-based searches can be slow in relational databases, especially when dealing with large datasets. This is because these databases are primarily designed for structured data and not optimized for full-text search. &lt;/p&gt;

&lt;p&gt;When performing such searches using operators like LIKE, the database often needs to examine each row individually to find matches. This row-by-row comparison is inefficient and can lead to timeouts or significant performance issues, particularly with large volumes of data.&lt;/p&gt;

&lt;p&gt;To optimize the text searches we can use Elastic search.&lt;br&gt;
Elasticsearch is a powerful, open-source search and analytics engine built on top of Apache Lucene. It's designed for fast, scalable, and flexible full-text search, data exploration, and real-time analytics.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Elastic search stores data in indexes&lt;/li&gt;
&lt;li&gt;During creation of index we can specify no of shards and no of replicas&lt;/li&gt;
&lt;li&gt;In a elastic search node cluster, load is balanced automatically&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To observe the power of elastic search, lets take an example of REST api built with express.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Create an express app&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;New express app is created with 2 routes - &lt;br&gt;
dbSearch and ElasticSearch&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%2Fxilln22iuw094bsxdxx3.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%2Fxilln22iuw094bsxdxx3.png" alt="new express app" width="800" height="752"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Set up mySQL and elastic search client&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;npm i mysql2 @elastic/elasticsearch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;💡 &lt;strong&gt;Note:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Elastic search service should be running on local port 9200.&lt;/li&gt;
&lt;li&gt;Elastic search requires creation of index before we can insert data , similar to a database in mysql.&lt;/li&gt;
&lt;li&gt;For index creation checkout the full source code added at the end of the article&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&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%2Fdocvq0c99w3u6dwiasgv.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%2Fdocvq0c99w3u6dwiasgv.png" alt="Mysql client setup" width="800" height="596"&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%2Fg0p5ytoacgfveroz6xy3.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%2Fg0p5ytoacgfveroz6xy3.png" alt="Elastic search client setup" width="800" height="316"&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Set up routes for REST api&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Route creation for path dbSearch which uses mySQL&lt;br&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%2Flcbjngu8k8u7lf195wfc.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%2Flcbjngu8k8u7lf195wfc.png" alt="Mysql router" width="800" height="314"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Route creation for path elasticSearch using elastic search&lt;br&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%2Fgyjfo3thxa7nj15rtehc.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%2Fgyjfo3thxa7nj15rtehc.png" alt="Elastic search router" width="800" height="968"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both the queries are similar.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Start up express server and test REST api&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Rest Api using mysql&lt;br&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%2F35k7bt75i8v6f15341ji.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%2F35k7bt75i8v6f15341ji.png" alt="Test mysql rest api" width="800" height="221"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rest Api using elastic search&lt;br&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%2F663i8u9cbb6uctodcc8s.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%2F663i8u9cbb6uctodcc8s.png" alt="Test elasticSearch rest api" width="800" height="160"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The search performed using elastic search is ~165% faster on average. &lt;br&gt;
This may vary according to the amount of data. The more data there is the more deviation we would notice.&lt;/p&gt;

&lt;p&gt;Full code here - &lt;a href="https://github.com/Analyst-Harsh/elastic-search-demo/tree/main/api-elastic-search" rel="noopener noreferrer"&gt;Github&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What are your thoughts on usage of elastic search?&lt;/p&gt;

</description>
      <category>elasticsearch</category>
      <category>express</category>
      <category>typescript</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
