<?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: Raza</title>
    <description>The latest articles on DEV Community by Raza (@raza_devv).</description>
    <link>https://dev.to/raza_devv</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%2F1113450%2F2b66c5b7-f366-4b59-a389-1bc55e344a39.jpeg</url>
      <title>DEV Community: Raza</title>
      <link>https://dev.to/raza_devv</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/raza_devv"/>
    <language>en</language>
    <item>
      <title>Changing Jenkins Port on Linux: A Step-by-Step Guide</title>
      <dc:creator>Raza</dc:creator>
      <pubDate>Thu, 23 Nov 2023 06:53:14 +0000</pubDate>
      <link>https://dev.to/raza_devv/changing-jenkins-port-on-linux-a-step-by-step-guide-4fne</link>
      <guid>https://dev.to/raza_devv/changing-jenkins-port-on-linux-a-step-by-step-guide-4fne</guid>
      <description>&lt;h2&gt;
  
  
  Introduction:
&lt;/h2&gt;

&lt;p&gt;Jenkins, a widely-used automation server in software development, sometimes requires tweaking, such as changing its default port. In this guide, we'll walk through the process of changing the Jenkins port on a Linux system. No tech jargon, just straightforward steps to help you make this adjustment seamlessly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Steps
&lt;/h2&gt;

&lt;p&gt;Step 1: Stop the Jenkins and find the Jenkins Configuration File.&lt;br&gt;
Locate the Jenkins file:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; sudo systemctl stop jenkins
 cd /etc/default/
 //Take a backup of the jenkins file.
 cp jenkins jenkins_backup
 sudo vim jenkins
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Edit the file, find &lt;code&gt;HTTP_PORT&lt;/code&gt; and modify it with your preferred port number. For instance:&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;After altering the port and saving, start Jenkins:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; sudo systemctl start jenkins
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Verify it by visiting &lt;a href="http://your_jenkins_instance_ip:8084"&gt;http://your_jenkins_instance_ip:8084&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Make sure jenkins is still not working on 8080 port or your previous port; incase it does , follow this &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo vim /usr/lib/systemd/system/jenkins.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Locate &lt;code&gt;Environment="JENKINS_PORT=8080"&lt;/code&gt;. Change the port number to new port number and save.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;systemctl daemon-reload
systemctl restart jenkins.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Keep in mind that adjusting the port could impact other services or tools relying on the standard Jenkins port (8080). Confirm that the new port is available and not in use by any other application on your system. Also, don't forget to modify firewall or security group settings if needed! 🚀&lt;/p&gt;

</description>
      <category>devops</category>
      <category>jenkins</category>
      <category>linux</category>
    </item>
    <item>
      <title>AWS Magic: Give Your Account a Cool Alias</title>
      <dc:creator>Raza</dc:creator>
      <pubDate>Mon, 20 Nov 2023 14:11:49 +0000</pubDate>
      <link>https://dev.to/raza_devv/aws-magic-give-your-account-a-cool-alias-2jo1</link>
      <guid>https://dev.to/raza_devv/aws-magic-give-your-account-a-cool-alias-2jo1</guid>
      <description>&lt;h3&gt;
  
  
  Introduction:
&lt;/h3&gt;

&lt;p&gt;Do you want to learn how to turn that boring AWS User Account ID into a cool alias to keep things simple and fun?&lt;/p&gt;

&lt;p&gt;This step-by-step guide is your ticket to making AWS a bit more personal.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Go to the AWS Management Console
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Log in to the AWS Management Console as a root user.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Step 2: Check Out the IAM Dashboard
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Once you're in, find and click on "Services" in the top left. In the "Security, Identity, &amp;amp; Compliance" part, click "IAM" or Search IAM on the search input.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsjgd1i76rd4x52qbqu8m.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsjgd1i76rd4x52qbqu8m.jpeg" alt="IAM Console" width="800" height="206"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Find IAM Dashboard
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;On the IAM dashboard, your User Account ID is right there. click create alias.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl1suqqgepp2de8f1bc1x.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl1suqqgepp2de8f1bc1x.jpeg" alt="IAM Dashboard" width="800" height="235"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Type Preferred alias in the Popup input and click create alias.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fktfr1ve70kudzcn7n1w7.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fktfr1ve70kudzcn7n1w7.jpeg" alt="Enter image meta" width="800" height="525"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: Check Out Your New Alias
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7gs1slkjo59ctpjar64o.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7gs1slkjo59ctpjar64o.jpeg" alt="Enter image meta" width="800" height="308"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Use the alias to log in. It will be useful, especially if you have multiple AWS accounts.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion:
&lt;/h3&gt;

&lt;p&gt;Great! You've a AWS User Account ID with a personal touch. This simple trick adds personality to your AWS adventure. So go ahead and explore AWS with your spiffy new alias!&lt;/p&gt;

&lt;p&gt;P.S.: Remember, nicknames should be unique and easiest, so choose wisely! 🚀✨&lt;/p&gt;

</description>
    </item>
    <item>
      <title>A Day in the Life of a DevOps Engineer</title>
      <dc:creator>Raza</dc:creator>
      <pubDate>Sun, 19 Nov 2023 18:47:30 +0000</pubDate>
      <link>https://dev.to/raza_devv/a-day-in-the-life-of-a-devops-engineer-30nn</link>
      <guid>https://dev.to/raza_devv/a-day-in-the-life-of-a-devops-engineer-30nn</guid>
      <description>&lt;h2&gt;
  
  
  A Day in the Life of a DevOps Engineer
&lt;/h2&gt;

&lt;p&gt;Hey folks! Let's have a little chat about what we do as a DevOps engineers. It's kind of like being the mastermind behind the scenes, making sure our software world ticks smoothly.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Infrastructure as Code (IaC):
&lt;/h3&gt;

&lt;p&gt;So, first things first. Imagine we're building a digital town for our software. we use tools like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Terraform&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Ansible&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CloudFormation&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Continuous Integration/Continuous Deployment (CI/CD):
&lt;/h3&gt;

&lt;p&gt;Next up, it's like being the conductor of an orchestra. We make sure our software plays its music without any hiccups. Tools like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Jenkins&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;GitLab CI/CD&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CircleCI&lt;/strong&gt; help me keep everything in harmony.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Containerization and Orchestration:
&lt;/h3&gt;

&lt;p&gt;We pack up our software into these neat little containers and use tools like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Docker&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Kubernetes&lt;/strong&gt; to make sure these containers dance together without any missteps.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. Cloud Services:
&lt;/h3&gt;

&lt;p&gt;Taking our show to the clouds, we manage our digital stuff on platforms like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;AWS&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Azure&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;GCP&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5. Monitoring and Logging:
&lt;/h3&gt;

&lt;p&gt;Always keeping an eye out, We set up tools to watch over our software's every move. Think:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Prometheus&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Grafana&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ELK Stack (Elasticsearch, Logstash, Kibana)&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  6. Security:
&lt;/h3&gt;

&lt;p&gt;Safety first, right? We use tools like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;HashiCorp Vault&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SonarQube&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Twistlock&lt;/strong&gt; to keep our digital town safe and sound.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  7. Collaboration and Communication:
&lt;/h3&gt;

&lt;p&gt;In our world, teamwork is the secret sauce. Tools like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Slack&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Jira&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Confluence&lt;/strong&gt; help us all work together seamlessly.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  8. Automated Testing:
&lt;/h3&gt;

&lt;p&gt;We bring in the tech magic to check if our software behaves. Tools like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Selenium&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;JUnit&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cucumber&lt;/strong&gt; automate these checks like a helping hand.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  9. Release Management:
&lt;/h3&gt;

&lt;p&gt;Planning the grand entrance of our software updates is crucial. Tools like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;GitFlow&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SemVer&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Jenkins Pipeline&lt;/strong&gt; help us stage the perfect debut.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  10. Configuration Management:
&lt;/h3&gt;

&lt;p&gt;Making sure everything runs smoothly, no matter where it is. Tools like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Ansible&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Puppet&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chef&lt;/strong&gt; make it happen.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  11. Documentation:
&lt;/h3&gt;

&lt;p&gt;We're the storytellers, creating guides so everyone gets our digital tale. Tools like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Confluence&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Markdown&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Git&lt;/strong&gt; help us spin the story.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  12. Incident Response and Troubleshooting:
&lt;/h3&gt;

&lt;p&gt;When things get tricky, we're the first responders, armed with tools like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;PagerDuty&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;New Relic&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Datadog&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  13. Performance Optimization:
&lt;/h3&gt;

&lt;p&gt;Finding and fixing what slows us down, using tools like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Google PageSpeed Insights&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Apache JMeter&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Gatling&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  14. Continuous Learning:
&lt;/h3&gt;

&lt;p&gt;Staying in the loop with the latest tech gossip by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reading tech blogs&lt;/li&gt;
&lt;li&gt;Attending conferences&lt;/li&gt;
&lt;li&gt;Taking online courses&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  15. Collaborative Tooling:
&lt;/h3&gt;

&lt;p&gt;Tools like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Slack&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Jira&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Confluence&lt;/strong&gt; keep our team in sync.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, as a DevOps engineer with over few years in the game, it's not just about the tech. It's about guiding the team, making smart decisions, and ensuring our software world runs like a well-oiled machine. Here's to keeping the digital magic alive! 🚀&lt;/p&gt;

</description>
    </item>
    <item>
      <title>A Quick Guide to Command Your Docker Containers</title>
      <dc:creator>Raza</dc:creator>
      <pubDate>Sat, 18 Nov 2023 09:44:32 +0000</pubDate>
      <link>https://dev.to/raza_devv/few-docker-commands-quick-reference-18m1</link>
      <guid>https://dev.to/raza_devv/few-docker-commands-quick-reference-18m1</guid>
      <description>&lt;h2&gt;
  
  
  Basic Container Operations
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Run a Container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-it&lt;/span&gt; ubuntu
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Starts a new interactive container using the Ubuntu image.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Build an Image
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker build &lt;span class="nt"&gt;-t&lt;/span&gt; my-custom-image:latest &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Creates a custom Docker image named 'my-custom-image' from the current directory.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Pull an Image
&lt;/h3&gt;



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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Downloads the latest version of the Nginx image from the Docker Hub.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Push an Image
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker push my-custom-image:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Uploads the custom image 'my-custom-image' to a Docker registry.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  List Images
&lt;/h3&gt;



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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Displays a list of locally available Docker images.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Container Lifecycle Management
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Stop a Container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker stop my_container
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Gracefully stops the running container 'my_container'.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Start a Container
&lt;/h3&gt;



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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Resumes execution of the stopped container 'my_container'.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Restart a Container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker restart my_container
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Stops and then starts the container 'my_container'.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Kill a Container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nb"&gt;kill&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; SIGTERM my_container
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Sends a termination signal to forcefully stop the running container 'my_container'.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Remove a Container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nb"&gt;rm &lt;/span&gt;my_container
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Deletes the container 'my_container'.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Image Management
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Remove an Image
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker rmi my-custom-image:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Deletes the image 'my-custom-image' with the latest tag.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Create Image from Changes
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker commit my_container my-custom-image:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Creates a new image 'my-custom-image' from changes made in a running container 'my_container'.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Save Images to Archive
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker save &lt;span class="nt"&gt;-o&lt;/span&gt; my-images.tar.gz my-custom-image:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Saves the image 'my-custom-image' with the latest tag to a tar archive.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Load Image from Archive
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker load &lt;span class="nt"&gt;-i&lt;/span&gt; my-images.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Loads an image from the tar archive 'my-images.tar.gz'.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Container Interaction
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Execute Command in Container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; my_container bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Runs an interactive bash shell in the running container 'my_container'.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Fetch Container Logs
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker logs my_container
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Retrieves and displays the logs of the container 'my_container'.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Inspect Container or Image
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker inspect my_container
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Retrieves detailed information about the container 'my_container'.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Copy Files Between Container and Host
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nb"&gt;cp &lt;/span&gt;my_container:/path/in/container /path/on/host
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Copies files or folders between the container 'my_container' and the local filesystem.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  System Cleanup and Maintenance
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Remove Unused Resources
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker system prune
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Cleans up stopped containers, dangling images, and unused networks and volumes.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Miscellaneous Commands
&lt;/h2&gt;

&lt;h3&gt;
  
  
  List Port Mappings
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker port my_container
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Shows the port mappings of the container 'my_container'.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Display Running Processes
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker top my_container
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Lists the running processes inside the container 'my_container'.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Manage Volumes
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker volume &lt;span class="nb"&gt;ls&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Lists the Docker volumes on the host.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Show Docker Version
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Displays information about the installed Docker version.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Show Changes in Container Filesystem
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker diff my_container
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Shows the filesystem changes made in the container 'my_container'.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Export Container Filesystem
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nb"&gt;export &lt;/span&gt;my_container &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; my_container_exported.tar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Exports the filesystem of the container 'my_container' to a tar archive.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Import Filesystem to Create Image
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker import my_container_exported.tar my-imported-image:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Imports the filesystem from the tar archive 'my_container_exported.tar' to create a new image 'my-imported-image' with the latest tag.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Docker Network Commands
&lt;/h2&gt;

&lt;h3&gt;
  
  
  List Docker Networks
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker network &lt;span class="nb"&gt;ls&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Displays a list of Docker networks.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Create a Docker Network
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker network create my_network
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Creates a new Docker network named 'my_network'.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Inspect Docker Network
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker network inspect my_network
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Retrieves detailed information about the Docker network 'my_network'.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Docker Registry Commands
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Docker Login
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Logs in to a Docker registry.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Docker Logout
&lt;/h3&gt;



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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Logs out from a Docker registry.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Docker Volume Commands
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Create a Docker Volume
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker volume create my_volume
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Creates a new Docker volume named 'my_volume'.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Inspect Docker Volume
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker volume inspect my_volume
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Retrieves detailed information about the Docker volume 'my_volume'.&lt;/em&gt;&lt;/p&gt;

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

&lt;h3&gt;
  
  
  Docker Compose Up
&lt;/h3&gt;



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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Starts services defined in a &lt;code&gt;docker-compose.yml&lt;/code&gt; file.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Docker Compose Down
&lt;/h3&gt;



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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Stops and removes containers, networks, and volumes defined in a &lt;code&gt;docker-compose.yml&lt;/code&gt; file.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>devops</category>
    </item>
    <item>
      <title>Refactoring Javascript code with Object Literals: A Clean and Readable Approach</title>
      <dc:creator>Raza</dc:creator>
      <pubDate>Tue, 04 Jul 2023 18:26:31 +0000</pubDate>
      <link>https://dev.to/raza_devv/simplifying-user-authentication-with-object-literals-a-clean-and-readable-approach-57kk</link>
      <guid>https://dev.to/raza_devv/simplifying-user-authentication-with-object-literals-a-clean-and-readable-approach-57kk</guid>
      <description>&lt;p&gt;This is and slightly modified article i wrote few years back on medium.&lt;br&gt;
&lt;a href="https://medium.com/@razamoh/js-code-refactoring-how-to-refactor-conditional-statements-use-object-literals-instead-669c1933f089"&gt;link&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Introduction:
&lt;/h2&gt;

&lt;p&gt;When it comes to user authentication or multiple payment types, we often encounter complex conditional statements that can quickly become hard to follow. But fear not! There's a neat trick we can use to make our code more readable and maintainable: object literals. In this article, I'll explore how object literals can simplify user authentication or any related scenarios and make our code shine.&lt;/p&gt;
&lt;h2&gt;
  
  
  The Initial Code:
&lt;/h2&gt;

&lt;p&gt;Imagine you have a chunk of code that handles user authentication using different methods such as email, social login, and one-time passwords (OTP). Let's take a look at the initial 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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;authenticateUser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;method&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;credentials&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;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;method&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;email&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;authenticateWithEmail&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;credentials&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;method&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;social&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;authenticateWithSocial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;credentials&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;method&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;otp&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;authenticateWithOTP&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;credentials&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Invalid authentication method.&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="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;authenticateWithEmail&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;credentials&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="c1"&gt;// Here's where we authenticate using email credentials&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;authenticateWithSocial&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;credentials&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="c1"&gt;// Here's where we authenticate using social credentials&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;authenticateWithOTP&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;credentials&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="c1"&gt;// Here's where we authenticate using OTP credentials&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Refactoring with Object Literals:
&lt;/h2&gt;

&lt;p&gt;To make our code cleaner and easier to read, we can leverage the power of object literals. Let's rewrite the code using this approach:&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;authenticationMethods&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;authenticateWithEmail&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;social&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;authenticateWithSocial&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;otp&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;authenticateWithOTP&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;authenticateUser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;method&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;credentials&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;authenticate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;authenticationMethods&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;method&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;authenticate&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nf"&gt;authenticate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;credentials&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Invalid authentication method.&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Let's Break it Down:
&lt;/h2&gt;

&lt;p&gt;In our refactored code, we create an object literal called authenticationMethods. This handy object maps each authentication method to its corresponding authentication function. By doing this, we can easily access the appropriate authentication function based on the provided method.&lt;/p&gt;

&lt;p&gt;Gone are the days of tangled if-else statements or lengthy switch cases. With object literals, our code becomes cleaner and more readable. If a new authentication method pops up in the future, all we need to do is update the authenticationMethods object without touching the authenticateUser function.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion:
&lt;/h2&gt;

&lt;p&gt;By utilising object literals, we can transform complex conditional statements into elegant and readable code. In this article, we've seen how this technique simplifies user authentication scenarios. Embracing this approach not only enhances the maintainability of our code but also makes it more understandable and enjoyable to work with.&lt;/p&gt;

&lt;p&gt;I'd love to hear your thoughts and answer any questions you might have. So go ahead, give it a try, and let me know how object literals elevate your code to new heights!&lt;/p&gt;

&lt;h2&gt;
  
  
  Alternate views
&lt;/h2&gt;

&lt;p&gt;Suggested by &lt;a class="mentioned-user" href="https://dev.to/jonrandy"&gt;@jonrandy&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The object literal is a bit of overkill here, since you effectively already have it on this. So, it can be made even simpler:&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;authenticateUser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;method&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;credentials&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;methodName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`authenticateWith&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;method&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;method&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;methodName&lt;/span&gt;&lt;span class="p"&gt;]&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;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Invalid authentication method.&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="nx"&gt;credentials&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way also scales to new authentication methods without having to change the code (providing you stick to the naming convention you provided) - making it more maintainable still.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>refactoring</category>
      <category>development</category>
    </item>
  </channel>
</rss>
