<?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: Ili Aliaj</title>
    <description>The latest articles on DEV Community by Ili Aliaj (@codewith_ili).</description>
    <link>https://dev.to/codewith_ili</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%2F1528451%2Ff66fb5f6-6a52-4bc0-a9d0-a98cb3e39ba1.png</url>
      <title>DEV Community: Ili Aliaj</title>
      <link>https://dev.to/codewith_ili</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/codewith_ili"/>
    <language>en</language>
    <item>
      <title>How to Run MongoDB in Docker</title>
      <dc:creator>Ili Aliaj</dc:creator>
      <pubDate>Sat, 16 Nov 2024 21:30:48 +0000</pubDate>
      <link>https://dev.to/codewith_ili/how-to-run-mongodb-in-docker-17c9</link>
      <guid>https://dev.to/codewith_ili/how-to-run-mongodb-in-docker-17c9</guid>
      <description>&lt;p&gt;Running MongoDB in Docker is an excellent way to set up a database without installing it directly on your local machine. This guide will show you how to use Docker to quickly spin up a MongoDB instance using the latest mongo:8 image.&lt;/p&gt;

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

&lt;p&gt;Before you begin, make sure you have the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Docker installed on your system (Docker Desktop for Windows/Mac, or Docker CLI for Linux).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Basic understanding of how Docker works.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;*&lt;em&gt;Step 1: Pull the MongoDB Image&lt;br&gt;
*&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Docker Hub provides an official MongoDB image. To ensure you’re using the latest MongoDB 8 version, pull the mongo:8 image with this command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker pull mongo:8&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command fetches the latest MongoDB 8 image from Docker Hub and makes it available locally.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Run MongoDB in a Container&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Run a container with the mongo:8 image using the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker run -d \&lt;br&gt;
  --name mongodb-container \&lt;br&gt;
  -p 27017:27017 \&lt;br&gt;
  -e MONGO_INITDB_ROOT_USERNAME=admin \&lt;br&gt;
  -e MONGO_INITDB_ROOT_PASSWORD=adminpassword \&lt;br&gt;
  mongo:8&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Breaking Down the Command:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;• docker run -d: Starts the container in detached mode.&lt;/p&gt;

&lt;p&gt;• --name mongodb-container: Assigns a name to the container (you can choose any name).&lt;/p&gt;

&lt;p&gt;• -p 27017:27017: Maps MongoDB’s default port 27017 to your local machine, making it accessible.&lt;/p&gt;

&lt;p&gt;•-e: Sets environment variables to configure the database:&lt;/p&gt;

&lt;p&gt;• MONGO_INITDB_ROOT_USERNAME: Sets the root username (e.g., admin).&lt;/p&gt;

&lt;p&gt;• MONGO_INITDB_ROOT_PASSWORD: Sets the root password (e.g., adminpassword).&lt;/p&gt;

&lt;p&gt;• mongo:8: &lt;br&gt;
Specifies the image to use.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Step 3: Verify the Container is Running&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Check if the container is running with the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker ps&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You should see something like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CONTAINER ID   IMAGE      COMMAND       STATUS         PORTS                     NAMES&lt;br&gt;
abcdef123456   mongo:8    "docker-entry..."   Up 5 minutes   0.0.0.0:27017-&amp;gt;27017/tcp   mongodb-container&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
This confirms MongoDB is running and accessible on &lt;/p&gt;

&lt;p&gt;&lt;code&gt;localhost:27017&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Step 4: Connect to MongoDB&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Using the Mongo Shell:&lt;/p&gt;

&lt;p&gt;If you have the MongoDB client installed locally, connect to the running container with:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mongo --host localhost --port 27017 -u admin -p adminpassword&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Using a GUI:&lt;/p&gt;

&lt;p&gt;Tools like MongoDB Compass or Robo 3T make it easy to interact with your database visually. Just connect to localhost:27017 and use the credentials:&lt;/p&gt;

&lt;p&gt;• Username: admin&lt;br&gt;
• Password: adminpassword&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Step 5: Persist Data with Volumes (Optional)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;By default, Docker containers are ephemeral, meaning all data will be lost when the container is removed. To persist MongoDB data, map a local directory to the container’s data directory.&lt;/p&gt;

&lt;p&gt;Run the container with a volume:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker run -d \&lt;br&gt;
  --name mongodb-container \&lt;br&gt;
  -p 27017:27017 \&lt;br&gt;
  -e MONGO_INITDB_ROOT_USERNAME=admin \&lt;br&gt;
  -e MONGO_INITDB_ROOT_PASSWORD=adminpassword \&lt;br&gt;
  -v /path/to/your/local/data:/data/db \&lt;br&gt;
  mongo:8&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;What Changed?&lt;/p&gt;

&lt;p&gt;• -&lt;code&gt;v /path/to/your/local/data:/data/db&lt;/code&gt; : Maps a local directory (/path/to/your/local/data) to MongoDB’s data directory (/data/db), ensuring data persists even after the container is removed.&lt;/p&gt;

&lt;p&gt;Step 6: Stop and Remove the Container&lt;/p&gt;

&lt;p&gt;When you’re done, you can stop the MongoDB container:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker stop mongodb-container&lt;/code&gt;&lt;/p&gt;

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

&lt;p&gt;Using Docker to run MongoDB is a simple and efficient way to manage your database. It saves time, ensures consistency, and keeps your local machine clean from unnecessary installations. By following these steps, you can set up a MongoDB instance with Docker in just a few minutes&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>docker</category>
      <category>mongodb</category>
      <category>database</category>
    </item>
    <item>
      <title>Why should you use Docker</title>
      <dc:creator>Ili Aliaj</dc:creator>
      <pubDate>Sat, 16 Nov 2024 21:11:31 +0000</pubDate>
      <link>https://dev.to/codewith_ili/why-should-you-use-docker-38h3</link>
      <guid>https://dev.to/codewith_ili/why-should-you-use-docker-38h3</guid>
      <description>&lt;p&gt;In the world of web development, one thing is certain: &lt;strong&gt;consistency is key&lt;/strong&gt;. Whether you’re working on a local project, deploying to production, or collaborating with a team, ensuring that everything works the same way everywhere is crucial. This is where Docker comes in.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;What is Docker?&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Docker is an open-source platform that automates the deployment, scaling, and management of applications inside containers. &lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;container&lt;/strong&gt; is like a lightweight, portable virtual machine that encapsulates your application and its dependencies, ensuring that it works uniformly across any environment. Think of it as a &lt;em&gt;box that holds everything your app needs to run&lt;/em&gt;, from the code to the operating system libraries.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Docker is not a virtual machine&lt;/strong&gt; (VM), though. It uses the host machine’s OS and isolates the application processes, making containers faster and more resource-efficient compared to VMs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Should You Learn Docker?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As developers, we all know how frustrating it can be to run into issues like:&lt;/p&gt;

&lt;p&gt;• “It works on my machine!” &lt;br&gt;
when a colleague can’t run the app.&lt;/p&gt;

&lt;p&gt;• Configuration headaches: trying to get the right versions of libraries, databases, and dependencies.&lt;/p&gt;

&lt;p&gt;• Inconsistent environments: different systems running different configurations, leading to bugs that are hard to reproduce.&lt;/p&gt;

&lt;p&gt;Docker &lt;em&gt;solves&lt;/em&gt; these problems by ensuring that your application, along with its environment, is packaged together and runs the same way on every machine—whether it’s your local machine, a testing server, or a production environment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why is Docker Helpful for Developers?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here are some key reasons why Docker is a must-learn tool for developers:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Consistency Across Environments&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With Docker, you can define your development environment in a Dockerfile, which specifies all the dependencies and configurations. This ensures that everyone on the team has the same environment, eliminating the “works on my machine” problem.&lt;/p&gt;

&lt;p&gt;Example Dockerfile:&lt;/p&gt;

&lt;p&gt;`# Use an official Node.js runtime as a parent image&lt;br&gt;
FROM node:14&lt;/p&gt;

&lt;h1&gt;
  
  
  Set the working directory
&lt;/h1&gt;

&lt;p&gt;WORKDIR /app&lt;/p&gt;

&lt;h1&gt;
  
  
  Install dependencies
&lt;/h1&gt;

&lt;p&gt;COPY package*.json ./&lt;br&gt;
RUN npm install&lt;/p&gt;

&lt;h1&gt;
  
  
  Copy the rest of the application
&lt;/h1&gt;

&lt;p&gt;COPY . .&lt;/p&gt;

&lt;h1&gt;
  
  
  Expose the port the app runs on
&lt;/h1&gt;

&lt;p&gt;EXPOSE 3000&lt;/p&gt;

&lt;h1&gt;
  
  
  Command to run the app
&lt;/h1&gt;

&lt;p&gt;CMD ["npm", "start"]`&lt;/p&gt;

&lt;p&gt;This Dockerfile sets up a Node.js environment. Once built, anyone with Docker can run the same environment by simply executing docker run.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Simplifies Dependency Management&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Running databases, services, or multiple versions of a stack can be complicated. With Docker, you can containerize these services so that they don’t interfere with each other. For example, you can run both MySQL and MongoDB side by side without worrying about configuration conflicts.&lt;/p&gt;

&lt;p&gt;Example docker-compose.yml to run a database container:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;version: '3'&lt;br&gt;
services:&lt;br&gt;
  db:&lt;br&gt;
    image: mysql:5.7&lt;br&gt;
    environment:&lt;br&gt;
      MYSQL_ROOT_PASSWORD: example&lt;br&gt;
    ports:&lt;br&gt;
      - "3306:3306"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This file automatically sets up MySQL for you, making it easy to connect your app to a database without hassle.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Portability and Reproducibility&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Docker containers can be easily shared, versioned, and stored on Docker Hub or a private registry. You can push and pull containers, making it incredibly easy to collaborate with other developers or deploy to a production server. Whether you’re switching machines or working on different teams, Docker guarantees that your app will run exactly the same way everywhere.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Faster Deployment and Testing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Docker allows you to quickly spin up containers for testing purposes. You can test your app in isolated environments without the need to worry about changing your local setup. This makes continuous integration (CI) and continuous deployment (CD) pipelines smoother, since Docker containers can easily be integrated into automated workflows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What Can You Do With Docker?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Docker has many use cases that can improve your development workflow:&lt;/p&gt;

&lt;p&gt;• Database Containers:&lt;br&gt;
Easily spin up and tear down databases for development and testing purposes without needing to install them on your local machine.&lt;/p&gt;

&lt;p&gt;• Development Environments: Docker can serve as a consistent and isolated environment for every developer working on the project, from front-end developers to back-end engineers.&lt;/p&gt;

&lt;p&gt;•Automated Deployments:&lt;br&gt;
Docker is widely used in deployment pipelines for automated testing, building, and pushing to production environments like AWS, Azure, or Google Cloud.&lt;/p&gt;

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

&lt;p&gt;Learning Docker is an &lt;strong&gt;investment&lt;/strong&gt; that pays off for almost every developer. It streamlines the development process, improves collaboration, and helps you manage dependencies and environments with ease. Whether you’re working on a small personal project or a large-scale enterprise application, Docker provides the flexibility and consistency needed to ensure your app runs smoothly in any environment.&lt;/p&gt;

&lt;p&gt;If you’re ready to start using Docker, there are plenty of tutorials and documentation available to guide you. &lt;strong&gt;The best part?&lt;/strong&gt; You don’t need to set up complicated virtual machines to test your applications—you can just spin up containers in a matter of minutes&lt;/p&gt;

</description>
      <category>docker</category>
      <category>webdev</category>
      <category>database</category>
      <category>programming</category>
    </item>
    <item>
      <title>Stop Getting Stuck Before You Even Start Coding: Plan Before You Execute</title>
      <dc:creator>Ili Aliaj</dc:creator>
      <pubDate>Sun, 06 Oct 2024 13:06:35 +0000</pubDate>
      <link>https://dev.to/codewith_ili/stop-getting-stuck-before-you-even-start-coding-plan-before-you-execute-27a1</link>
      <guid>https://dev.to/codewith_ili/stop-getting-stuck-before-you-even-start-coding-plan-before-you-execute-27a1</guid>
      <description>&lt;p&gt;How many times have you thought of a new project idea, feeling all excited and hyped up to code it? But then, as soon as you open your code editor, you just get stuck. No lines of code come to mind. You don’t know where to start or what to even write.&lt;/p&gt;

&lt;p&gt;This happens to many of us, and it’s usually because of bad planning—or no planning at all. Let’s face it, as coders, we’ve all been there.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Plan Before You Code&lt;/strong&gt;&lt;br&gt;
Before diving into your code editor, you need to have a structured plan in mind. A clear roadmap can save you a lot of frustration and confusion. Here's how you can approach it:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Create a User Flow&lt;/strong&gt;&lt;br&gt;
Write everything down, from the moment the user opens your web app to the point they leave. Map out all interactions. This helps you visualize the flow of your application and understand how users will navigate through it.&lt;/p&gt;

&lt;p&gt;For example, if you’re building a simple weather app, you need to detail how users will search for the weather, view results, and maybe even switch locations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Break the Project into Small, Manageable Tasks&lt;/strong&gt;&lt;br&gt;
Once you’ve got the user flow in mind, break your project down into smaller coding tasks—think of it as solving a puzzle piece by piece. Each task should represent a small step towards building the whole project.&lt;/p&gt;

&lt;p&gt;Using a weather app example, here’s how you can break it down:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fetch weather data from an API.&lt;/li&gt;
&lt;li&gt;Display the weather data on the user interface.&lt;/li&gt;
&lt;li&gt;Accept user input for different location searches.
Each of these steps is manageable on its own, and tackling them one by one makes the project less overwhelming.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Start Coding, One Task at a Time&lt;/strong&gt;&lt;br&gt;
Now that you’ve split the project into smaller tasks, it’s time to start coding. Focus on one task at a time and gradually piece everything together. This step-by-step approach not only keeps you from getting stuck, but it also gives you a sense of accomplishment as you complete each part.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final Thoughts&lt;/strong&gt;&lt;br&gt;
The tips above may seem simple, but they can help you tackle coding projects—whether small or massive—with confidence. Proper planning ensures that you always know your next step and avoid getting overwhelmed.&lt;/p&gt;

&lt;p&gt;So, next time you think of a new project, don’t just dive into your editor. Plan before you execute, and you’ll be surprised at how much smoother the coding process becomes!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>coding</category>
      <category>devjournal</category>
    </item>
    <item>
      <title>Top 2 React Hooks</title>
      <dc:creator>Ili Aliaj</dc:creator>
      <pubDate>Wed, 25 Sep 2024 18:17:10 +0000</pubDate>
      <link>https://dev.to/codewith_ili/top-2-react-hooks-2bl9</link>
      <guid>https://dev.to/codewith_ili/top-2-react-hooks-2bl9</guid>
      <description>&lt;p&gt;&lt;strong&gt;What are React hooks?&lt;/strong&gt;&lt;br&gt;
Hooks provide functional components the ability to manage state &amp;amp; side-effects. They were first introduced in React v16.8 and different hooks have been added since then. Today we will be talking about MY top 3 hooks which i use the most.&lt;/p&gt;

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

&lt;ol&gt;
&lt;li&gt;The useState hook
**
It let's you add a state variable inside a component.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;const [age, setAge] = useState(18)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The above is a simple example to how this hook is defined.&lt;br&gt;
The useState hooks takes a paramter (18) as an initial state for the defined variable (age) and provides us with an array of two values:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;(age) which returns the current state&lt;/li&gt;
&lt;li&gt;(setAge) which is a setter function that 
 lets you update the state.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here is how a setter function works: &lt;br&gt;
&lt;code&gt;&lt;br&gt;
function incrementAge(){&lt;br&gt;
  setAge(a =&amp;gt; a + 1)&lt;br&gt;
}&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Each time this function is called, the setter function will update the state based on the last state.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. The useEffect hook&lt;/strong&gt;&lt;br&gt;
It lets you synchronize your component with an external system like the DOM, networks... .&lt;/p&gt;

&lt;p&gt;&lt;code&gt;useEffect(() =&amp;gt; {&lt;br&gt;
    const connection = createConnection(serverUrl, roomId);&lt;br&gt;
    connection.connect();&lt;br&gt;
    return () =&amp;gt; {&lt;br&gt;
      connection.disconnect();&lt;br&gt;
    };&lt;br&gt;
  }, [serverUrl, roomId]);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The useEffect hook takes 2 parameters, a &lt;strong&gt;function&lt;/strong&gt; and a &lt;strong&gt;dependency array&lt;/strong&gt;. The function will only execute when the variables in the dependency array, which comes after the function, change it's value or state. If the dependency array is empty, the function will run each time the component gets rendered.&lt;/p&gt;

&lt;p&gt;These are just two of many other hooks in React, they are the most common and the most useful in different situations.&lt;/p&gt;

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