<?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: Hardik Gayner </title>
    <description>The latest articles on DEV Community by Hardik Gayner  (@imhardik).</description>
    <link>https://dev.to/imhardik</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%2F1384536%2F416e1958-7ec7-43e7-93b6-c5e3ab6b4f02.jpg</url>
      <title>DEV Community: Hardik Gayner </title>
      <link>https://dev.to/imhardik</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/imhardik"/>
    <language>en</language>
    <item>
      <title>🧠 How to Stay Updated in Tech as a Software Developer (With a Touch of AI) ?</title>
      <dc:creator>Hardik Gayner </dc:creator>
      <pubDate>Sat, 05 Apr 2025 05:51:08 +0000</pubDate>
      <link>https://dev.to/imhardik/how-to-stay-updated-in-tech-as-a-software-developer-with-a-touch-of-ai--3nfj</link>
      <guid>https://dev.to/imhardik/how-to-stay-updated-in-tech-as-a-software-developer-with-a-touch-of-ai--3nfj</guid>
      <description>&lt;p&gt;The tech industry is evolving faster than ever — especially with AI shaking things up daily. If you’re a software developer or engineer, staying updated isn’t just “nice to have” anymore... it’s essential.&lt;/p&gt;

&lt;p&gt;So, how do we keep up without burning out?&lt;/p&gt;

&lt;p&gt;Let’s break down &lt;strong&gt;actionable ways&lt;/strong&gt; you can stay current, learn faster, and level up — all without falling into the content-overload trap.&lt;/p&gt;




&lt;h2&gt;
  
  
  🚀 1. Curate Your Daily Feed (Stop Doom-Scrolling)
&lt;/h2&gt;

&lt;p&gt;Don't try to follow everything. Just follow the &lt;em&gt;right&lt;/em&gt; things:&lt;/p&gt;

&lt;h3&gt;
  
  
  📩 Newsletters:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.tldrnewsletter.com/" rel="noopener noreferrer"&gt;&lt;strong&gt;TLDR&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://newsletter.pragmaticengineer.com/" rel="noopener noreferrer"&gt;&lt;strong&gt;The Pragmatic Engineer&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.bensbites.co/" rel="noopener noreferrer"&gt;&lt;strong&gt;Ben’s Bites&lt;/strong&gt; (AI-focused)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.hackernewsletter.com/" rel="noopener noreferrer"&gt;&lt;strong&gt;Hacker Newsletter&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;They summarize what’s new in dev, startups, tools, and AI in under 5 minutes.&lt;/p&gt;

&lt;h3&gt;
  
  
  🎧 Podcasts:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;The Changelog&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Lex Fridman Podcast&lt;/em&gt; (long-form, deep dives)&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;AI Daily Brief&lt;/em&gt; (short and sweet)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  📺 YouTube Channels:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/c/Fireship" rel="noopener noreferrer"&gt;&lt;strong&gt;Fireship&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/@ThePrimeagen" rel="noopener noreferrer"&gt;&lt;strong&gt;The Primeagen&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/@TwoMinutePapers" rel="noopener noreferrer"&gt;&lt;strong&gt;Two Minute Papers&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🤖 2. Use AI to Learn About AI (and Everything Else)
&lt;/h2&gt;

&lt;p&gt;Let AI tools be your &lt;strong&gt;learning assistant&lt;/strong&gt;, not just a coding helper.&lt;/p&gt;

&lt;p&gt;Use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;ChatGPT / Claude / Gemini&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;GitHub Copilot / Codeium&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Perplexity AI&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ask questions like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;“Summarize the LangChain framework &lt;span class="k"&gt;in &lt;/span&gt;100 words.”
“What&lt;span class="s1"&gt;'s the difference between Retrieval-Augmented Generation and fine-tuning?”
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let them guide you to docs, tutorials, or even give you practice problems. Think of them as your personalized Stack Overflow, but faster.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔁 3. Build in Public (Stay Accountable &amp;amp; Learn Fast)
&lt;/h2&gt;

&lt;p&gt;Start a side project using new tech. Document the journey right here on DEV. It helps you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stay accountable&lt;/li&gt;
&lt;li&gt;Learn by teaching&lt;/li&gt;
&lt;li&gt;Attract opportunities&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;AI-powered note-taker&lt;/li&gt;
&lt;li&gt;LLM-based code reviewer&lt;/li&gt;
&lt;li&gt;Real-time app with WebSockets or WebRTC&lt;/li&gt;
&lt;li&gt;Anything that makes you say: &lt;em&gt;“That looks fun.”&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Bonus: Open-source it. The community might just help you improve it too!&lt;/p&gt;




&lt;h2&gt;
  
  
  🧵 4. Follow Devs &amp;gt; Headlines
&lt;/h2&gt;

&lt;p&gt;Some of the best tech insights come from indie devs or engineers working on real problems. You don’t need to follow every news outlet — just follow a few sharp minds.&lt;/p&gt;

&lt;h3&gt;
  
  
  On Twitter (X), LinkedIn, and here on DEV:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://twitter.com/swyx" rel="noopener noreferrer"&gt;@swyx&lt;/a&gt; (AI + developer tools)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://twitter.com/rauchg" rel="noopener noreferrer"&gt;@floydophone (Guillermo Rauch)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://twitter.com/karpathy" rel="noopener noreferrer"&gt;@andrejkarpathy&lt;/a&gt; (AI deep dives)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://twitter.com/thekitze" rel="noopener noreferrer"&gt;@thekitze&lt;/a&gt; (dev + humor + hot takes)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  📚 5. Take Learning Seriously (But Make It Fun)
&lt;/h2&gt;

&lt;p&gt;You don’t need to sign up for 12-week bootcamps — but some structured learning helps.&lt;/p&gt;

&lt;h3&gt;
  
  
  Great resources:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://frontendmasters.com/" rel="noopener noreferrer"&gt;Frontend Masters&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://coursera.org/" rel="noopener noreferrer"&gt;Coursera&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://huggingface.co/learn" rel="noopener noreferrer"&gt;Hugging Face Course (for AI)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://buildspace.so/" rel="noopener noreferrer"&gt;Buildspace&lt;/a&gt; (project-based AI/web3 learning)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Set a simple rule:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;🧩 Learn 1 new thing every week. Build 1 small thing every month.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  💬 6. Join Communities (They’ll Save You Time)
&lt;/h2&gt;

&lt;p&gt;Being active in a dev community = early access to trends, tools, job leads, and support.&lt;/p&gt;

&lt;h3&gt;
  
  
  Where to hang out:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;DEV.to&lt;/strong&gt; ❤️&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Discord&lt;/strong&gt; (try: Learn AI Together, LangChain, Vercel’s community)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reddit:&lt;/strong&gt; &lt;code&gt;r/learnprogramming&lt;/code&gt;, &lt;code&gt;r/MachineLearning&lt;/code&gt;, &lt;code&gt;r/Frontend&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Slack:&lt;/strong&gt; RemoteOK, AI Town, etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ask dumb questions. Share smart answers. Grow together.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧭 Final Thoughts
&lt;/h2&gt;

&lt;p&gt;You don’t need to master &lt;em&gt;everything&lt;/em&gt;. Tech isn’t about knowing it all — it’s about &lt;strong&gt;knowing what’s worth learning next&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let AI be your copilot. Let curiosity lead. And most importantly: &lt;strong&gt;keep building.&lt;/strong&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;If this helped, leave a ❤️ or drop your go-to tech update habits in the comments — let’s learn from each other!&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;Would you like me to add a cover image suggestion or meta description for the blog?&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>ai</category>
      <category>career</category>
    </item>
    <item>
      <title>How to Win Your First Hackathon: A Complete Guide</title>
      <dc:creator>Hardik Gayner </dc:creator>
      <pubDate>Wed, 26 Feb 2025 15:03:03 +0000</pubDate>
      <link>https://dev.to/imhardik/how-to-win-your-first-hackathon-a-complete-guide-4dkl</link>
      <guid>https://dev.to/imhardik/how-to-win-your-first-hackathon-a-complete-guide-4dkl</guid>
      <description>&lt;p&gt;Participating in a hackathon is an exciting and rewarding experience. Whether you’re a beginner or an aspiring tech enthusiast, winning your first hackathon can feel like a daunting task. But with the right strategy, teamwork, and innovation, you can turn your ideas into a winning project! &lt;/p&gt;

&lt;p&gt;Having won &lt;strong&gt;RTHack&lt;/strong&gt; twice in a row, I’ve learned a few key lessons that can help you build a winning hackathon project. Here’s everything you need to know to increase your chances of success. &lt;/p&gt;




&lt;h2&gt;
  
  
  1. Choose the Right Team 🤝
&lt;/h2&gt;

&lt;p&gt;Your team can make or break your hackathon experience. Look for teammates with &lt;strong&gt;complementary skills&lt;/strong&gt; – a mix of backend developers, frontend designers, and idea-driven individuals. Communication is key, so ensure everyone is on the same page.&lt;/p&gt;

&lt;p&gt;✅ Find teammates who are skilled but also &lt;strong&gt;collaborative&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
✅ Assign roles based on strengths (coding, design, pitching, etc.)&lt;br&gt;&lt;br&gt;
✅ Keep a &lt;strong&gt;positive and problem-solving mindset&lt;/strong&gt; throughout the event&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Understand the Problem Statement Clearly 📌
&lt;/h2&gt;

&lt;p&gt;A well-defined &lt;strong&gt;problem statement&lt;/strong&gt; is the foundation of a winning project. Before jumping into coding, spend time analyzing what the challenge demands.&lt;/p&gt;

&lt;p&gt;** Example: ** At RTHack, we focused on automating attendance systems to combat fraud. We recognized significant challenges, such as manual errors and proxy attendance, and developed a QR-based geo-fenced solution to address these problems.  &lt;/p&gt;

&lt;p&gt;✅ Identify the &lt;strong&gt;pain points&lt;/strong&gt; and what judges are expecting&lt;br&gt;&lt;br&gt;
✅ Break the problem down into &lt;strong&gt;smaller actionable tasks&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
✅ Think about real-world applications &amp;amp; user impact  &lt;/p&gt;




&lt;h2&gt;
  
  
  3. Keep It Simple but Impactful 💡
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;winning hackathon project&lt;/strong&gt; is not always the most complex one. It’s about solving a real problem efficiently. Instead of overcomplicating, focus on building a &lt;strong&gt;functional prototype&lt;/strong&gt; that showcases your idea effectively.&lt;/p&gt;

&lt;p&gt;✅ Prioritize &lt;strong&gt;core functionality&lt;/strong&gt; over fancy features&lt;br&gt;&lt;br&gt;
✅ Use &lt;strong&gt;MVP (Minimum Viable Product)&lt;/strong&gt; approach: a simple yet effective model&lt;br&gt;&lt;br&gt;
✅ Ensure your solution is &lt;strong&gt;scalable and practical&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Leverage the Right Technology Stack 🛠️
&lt;/h2&gt;

&lt;p&gt;Your tech stack should be &lt;strong&gt;efficient, scalable, and suitable for the problem&lt;/strong&gt; you’re solving. Use technologies you’re comfortable with, but don’t shy away from learning new tools if needed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; In our attendance project, we used:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Frontend:&lt;/strong&gt; React.js + TailwindCSS + ShadCN UI (for a clean UI)
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Backend:&lt;/strong&gt; PHP (to handle user authentication &amp;amp; QR generation)
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Database:&lt;/strong&gt; MySQL with phpMyAdmin (for managing student records)
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bluetooth-based geo-fencing&lt;/strong&gt; (to prevent proxy attendance)
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;✅ Pick a tech stack that balances &lt;strong&gt;speed and functionality&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
✅ Ensure your solution integrates &lt;strong&gt;seamlessly&lt;/strong&gt; with real-world systems&lt;br&gt;&lt;br&gt;
✅ Keep your &lt;strong&gt;code clean and modular&lt;/strong&gt; to avoid last-minute debugging nightmares  &lt;/p&gt;




&lt;h2&gt;
  
  
  5. Time Management is Key ⏳
&lt;/h2&gt;

&lt;p&gt;Hackathons are fast-paced, and time flies quickly. Plan your project &lt;strong&gt;efficiently&lt;/strong&gt; to avoid last-minute rush and unfinished work.&lt;/p&gt;

&lt;p&gt;✅ Divide work into &lt;strong&gt;milestones&lt;/strong&gt; and track progress&lt;br&gt;&lt;br&gt;
✅ Set strict deadlines for each feature/module&lt;br&gt;&lt;br&gt;
✅ Ensure enough time for &lt;strong&gt;testing and debugging&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  6. Make Your Project Stand Out 🌟
&lt;/h2&gt;

&lt;p&gt;Judges see multiple projects, so make yours &lt;strong&gt;memorable&lt;/strong&gt; by focusing on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Innovation&lt;/strong&gt;: Does your solution solve the problem in a unique way?
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;User Experience (UX)&lt;/strong&gt;: Is it easy to use? Does it have a clean UI?
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Impact&lt;/strong&gt;: How useful is it in real-world scenarios?
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A simple, well-thought-out solution with a great &lt;strong&gt;presentation&lt;/strong&gt; is better than a complex project with bugs. &lt;/p&gt;




&lt;h2&gt;
  
  
  7. Prepare a Strong Pitch 🎤
&lt;/h2&gt;

&lt;p&gt;Even the best project won’t win without a &lt;strong&gt;great presentation&lt;/strong&gt;. Your pitch should be &lt;strong&gt;clear, concise, and compelling&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;✅ Explain the &lt;strong&gt;problem, your solution, and the impact&lt;/strong&gt; in a structured way&lt;br&gt;&lt;br&gt;
✅ Keep the demo &lt;strong&gt;short and effective&lt;/strong&gt; – showcase the key features&lt;br&gt;&lt;br&gt;
✅ Be confident, and &lt;strong&gt;anticipate judges’ questions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; Live demos work best! If possible, showcase your project in action instead of just slides.&lt;/p&gt;




&lt;h2&gt;
  
  
  8. Stay Positive and Have Fun! 🚀
&lt;/h2&gt;

&lt;p&gt;Winning is great, but the real value of a hackathon is &lt;strong&gt;learning and networking&lt;/strong&gt;. Enjoy the process, collaborate with others, and build something meaningful.&lt;/p&gt;

&lt;p&gt;✅ Stay &lt;strong&gt;motivated&lt;/strong&gt;, even if things go wrong&lt;br&gt;&lt;br&gt;
✅ Be &lt;strong&gt;open to feedback&lt;/strong&gt; from judges and mentors&lt;br&gt;&lt;br&gt;
✅ Make connections with fellow participants for future opportunities  &lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Winning a hackathon isn’t just about coding—it’s about &lt;strong&gt;solving problems creatively, working as a team, and presenting effectively&lt;/strong&gt;. With &lt;strong&gt;clear goals, the right strategy, and a bit of practice&lt;/strong&gt;, you’ll be on your way to winning your first hackathon! 💪&lt;/p&gt;

&lt;p&gt;If you’re planning to participate in one soon, go for it with confidence. You’ve got this! 🚀 &lt;/p&gt;

&lt;h1&gt;
  
  
  HackathonTips #WinningMindset #Innovation #Tech
&lt;/h1&gt;

</description>
      <category>hackathon</category>
      <category>programming</category>
      <category>php</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Implementing Authentication Using JWT and Passport.js: A Beginner’s Guide</title>
      <dc:creator>Hardik Gayner </dc:creator>
      <pubDate>Wed, 19 Feb 2025 08:06:08 +0000</pubDate>
      <link>https://dev.to/imhardik/implementing-authentication-using-jwt-and-passportjs-a-beginners-guide-ckf</link>
      <guid>https://dev.to/imhardik/implementing-authentication-using-jwt-and-passportjs-a-beginners-guide-ckf</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Authentication is a crucial part of web applications, ensuring that only authorized users can access certain resources. One of the most secure and scalable authentication methods is &lt;strong&gt;JWT (JSON Web Token)&lt;/strong&gt; authentication. In this guide, we will implement JWT authentication using &lt;strong&gt;Passport.js&lt;/strong&gt;, a popular authentication middleware for Node.js.  &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What is JWT?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;JSON Web Token (JWT)&lt;/strong&gt; is a compact, URL-safe token format used for securely transmitting information between parties as a JSON object. It consists of three parts:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Header&lt;/strong&gt; – Contains metadata about the token (e.g., algorithm used).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Payload&lt;/strong&gt; – Contains user-related data (e.g., user ID).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Signature&lt;/strong&gt; – Ensures the token's integrity and authenticity.
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Why Use Passport.js?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Passport.js&lt;/strong&gt; is a middleware that simplifies authentication in Node.js applications. It supports various strategies, including &lt;strong&gt;JWT authentication&lt;/strong&gt;.  &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Project Setup&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 1: Initialize a Node.js Project&lt;/strong&gt;
&lt;/h3&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;jwt-auth-example
&lt;span class="nb"&gt;cd &lt;/span&gt;jwt-auth-example
npm init &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Step 2: Install Required Dependencies&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;express passport passport-jwt jsonwebtoken dotenv bcryptjs mongoose
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;express&lt;/code&gt; – Web framework for Node.js
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;passport&lt;/code&gt; – Authentication middleware
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;passport-jwt&lt;/code&gt; – JWT strategy for Passport.js
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;jsonwebtoken&lt;/code&gt; – Library for generating JWTs
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;dotenv&lt;/code&gt; – Loads environment variables
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;bcryptjs&lt;/code&gt; – Hashes passwords securely
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;mongoose&lt;/code&gt; – MongoDB ORM
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Building the Authentication System&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 3: Create the Folder Structure&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;jwt-auth-example
│── config/
│   ├── passport.js
│── models/
│   ├── User.js
│── routes/
│   ├── auth.js
│── server.js
│── .env
│── package.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Step 4: Setup MongoDB and User Model&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Connect to MongoDB&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Create a &lt;code&gt;.env&lt;/code&gt; file and add your &lt;strong&gt;MongoDB connection string&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;MONGO_URI=mongodb://localhost:27017/jwt-auth
JWT_SECRET=your_secret_key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;strong&gt;Create &lt;code&gt;User.js&lt;/code&gt; Model&lt;/strong&gt; (inside &lt;code&gt;models/&lt;/code&gt; folder)
&lt;/h4&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;mongoose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;mongoose&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;UserSchema&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;mongoose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Schema&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;username&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="nb"&gt;String&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="na"&gt;unique&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="na"&gt;email&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="nb"&gt;String&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="na"&gt;unique&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="na"&gt;password&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="nb"&gt;String&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="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="nx"&gt;mongoose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;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;UserSchema&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Step 5: Configure Passport.js for JWT Authentication&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Create &lt;code&gt;passport.js&lt;/code&gt; (inside &lt;code&gt;config/&lt;/code&gt; folder)&lt;/strong&gt;
&lt;/h4&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;JwtStrategy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;passport-jwt&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;Strategy&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;ExtractJwt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;passport-jwt&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;ExtractJwt&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;User&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;../models/User&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;dotenv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;dotenv&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;dotenv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;config&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;opts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;jwtFromRequest&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ExtractJwt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromAuthHeaderAsBearerToken&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="na"&gt;secretOrKey&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;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;JWT_SECRET&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;passport&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="nx"&gt;passport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;JwtStrategy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;opts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;jwt_payload&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;done&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;try&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;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;jwt_payload&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&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;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;done&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;done&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&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="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&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="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Step 6: Create Authentication Routes&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Create &lt;code&gt;auth.js&lt;/code&gt; (inside &lt;code&gt;routes/&lt;/code&gt; folder)&lt;/strong&gt;
&lt;/h4&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;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;express&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;bcrypt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;bcryptjs&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;jwt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;jsonwebtoken&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;passport&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;passport&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;User&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;../models/User&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;dotenv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;dotenv&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;dotenv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;config&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;router&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Register Route&lt;/span&gt;
&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/register&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;password&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findOne&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;email&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;user&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;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;User already exists&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;hashedPassword&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;bcrypt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;hashedPassword&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;User registered successfully&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;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Server error&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="c1"&gt;// Login Route&lt;/span&gt;
&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/login&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;password&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;try&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;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findOne&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;email&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="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;user&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;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;User not found&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;isMatch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;bcrypt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;password&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="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;isMatch&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;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Invalid credentials&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;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;username&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="nx"&gt;jwt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sign&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nx"&gt;payload&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;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;JWT_SECRET&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;expiresIn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1h&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;err&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;token&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;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;token&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="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Server error&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="c1"&gt;// Protected Route&lt;/span&gt;
&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/profile&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;passport&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;jwt&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;session&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&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="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&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="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="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Step 7: Set Up the Server&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Create &lt;code&gt;server.js&lt;/code&gt;&lt;/strong&gt;
&lt;/h4&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;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;express&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;mongoose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;mongoose&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;dotenv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;dotenv&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;passport&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;passport&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;authRoutes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&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;./routes/auth&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;dotenv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;config&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;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

&lt;span class="nx"&gt;mongoose&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&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;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;MONGO_URI&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;useNewUrlParser&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="na"&gt;useUnifiedTopology&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="nf"&gt;then&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="nf"&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;MongoDB connected&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;catch&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;err&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="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="nf"&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;./config/passport&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nx"&gt;passport&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;passport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;initialize&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/api/auth&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;authRoutes&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;PORT&lt;/span&gt; &lt;span class="o"&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;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PORT&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;PORT&lt;/span&gt;&lt;span class="p"&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Server running on port &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;PORT&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Testing the Authentication System&lt;/strong&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Start the Server&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   node server.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Register a User&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   curl &lt;span class="nt"&gt;-X&lt;/span&gt; POST http://localhost:5000/api/auth/register &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'{"username": "hardik", "email": "hardik@example.com", "password": "123456"}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Login to Get a Token&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   curl &lt;span class="nt"&gt;-X&lt;/span&gt; POST http://localhost:5000/api/auth/login &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'{"email": "hardik@example.com", "password": "123456"}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Copy the received &lt;strong&gt;JWT token&lt;/strong&gt;.

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Access the Protected Route&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   curl &lt;span class="nt"&gt;-X&lt;/span&gt; GET http://localhost:5000/api/auth/profile &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Authorization: Bearer YOUR_JWT_TOKEN"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In this guide, we implemented &lt;strong&gt;JWT authentication&lt;/strong&gt; using &lt;strong&gt;Passport.js&lt;/strong&gt; in a Node.js application. We covered:&lt;br&gt;&lt;br&gt;
✅ User registration &amp;amp; password hashing&lt;br&gt;&lt;br&gt;
✅ User login with JWT generation&lt;br&gt;&lt;br&gt;
✅ Protecting routes using Passport.js  &lt;/p&gt;

&lt;p&gt;This approach ensures &lt;strong&gt;secure authentication&lt;/strong&gt; in modern web applications. 🚀&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>authentication</category>
      <category>javascript</category>
      <category>mern</category>
    </item>
    <item>
      <title>How I Built My First Full Stack Project: A Blog Website Using MERN</title>
      <dc:creator>Hardik Gayner </dc:creator>
      <pubDate>Sat, 15 Feb 2025 07:57:08 +0000</pubDate>
      <link>https://dev.to/imhardik/how-i-built-my-first-full-stack-project-a-blog-website-using-mern-40bp</link>
      <guid>https://dev.to/imhardik/how-i-built-my-first-full-stack-project-a-blog-website-using-mern-40bp</guid>
      <description>&lt;p&gt;Building my first full-stack project using the MERN (MongoDB, Express.js, React, and Node.js) stack was an exciting journey. I wanted to create a blog website where users could write, edit, and share their thoughts. In this blog post, I'll describe how I built it, the challenges I faced, and the lessons I learned.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I Chose the MERN Stack
&lt;/h2&gt;

&lt;p&gt;The MERN stack is widely used for building modern web applications. Here’s why I chose it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;MongoDB&lt;/strong&gt;: A NoSQL database that stores data in a flexible JSON-like format.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Express.js&lt;/strong&gt;: A minimal and powerful backend framework for Node.js.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;React.js&lt;/strong&gt;: A fast and efficient frontend library for building interactive UI.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Node.js&lt;/strong&gt;: A runtime environment that allows JavaScript to run on the server.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Features of the Blog Website
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;User authentication (Sign-up, Login, Logout)&lt;/li&gt;
&lt;li&gt;Create, read, update, and delete (CRUD) blog posts&lt;/li&gt;
&lt;li&gt;Image upload for blog posts&lt;/li&gt;
&lt;li&gt;Commenting system&lt;/li&gt;
&lt;li&gt;Responsive UI with React&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Tech Stack &amp;amp; Tools Used
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Frontend&lt;/strong&gt;: React.js, React Router, Axios, Tailwind CSS&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Backend&lt;/strong&gt;: Node.js, Express.js, bcrypt.js (for password hashing), JWT (for authentication), Multer (for image uploads)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Database&lt;/strong&gt;: MongoDB (Atlas)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deployment&lt;/strong&gt;: Vercel (Frontend), Render (Backend &amp;amp; Database)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Step-by-Step Development Process
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Setting Up the Backend (Express &amp;amp; MongoDB)
&lt;/h3&gt;

&lt;p&gt;I started by setting up the server using &lt;strong&gt;Express.js&lt;/strong&gt; and connecting it to &lt;strong&gt;MongoDB Atlas&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Installed dependencies:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  npm init &lt;span class="nt"&gt;-y&lt;/span&gt;
  npm &lt;span class="nb"&gt;install &lt;/span&gt;express mongoose cors dotenv bcryptjs jsonwebtoken multer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Created an &lt;code&gt;index.js&lt;/code&gt; file and set up the basic Express server.&lt;/li&gt;
&lt;li&gt;Connected MongoDB using Mongoose and created models for users and blog posts.&lt;/li&gt;
&lt;li&gt;Implemented authentication using &lt;strong&gt;JWT&lt;/strong&gt; and &lt;strong&gt;bcrypt.js&lt;/strong&gt; for password encryption.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Building the Frontend (React.js)
&lt;/h3&gt;

&lt;p&gt;Once the backend was ready, I moved to the frontend using &lt;strong&gt;React.js&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Installed dependencies:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  npx create-react-app blog-client
  &lt;span class="nb"&gt;cd &lt;/span&gt;blog-client
  npm &lt;span class="nb"&gt;install &lt;/span&gt;axios react-router-dom
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Created routes for:

&lt;ul&gt;
&lt;li&gt;Homepage (showing all blogs)&lt;/li&gt;
&lt;li&gt;Single blog post page&lt;/li&gt;
&lt;li&gt;Create/Edit/Delete blog post pages&lt;/li&gt;
&lt;li&gt;Authentication (Login &amp;amp; Register)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Used &lt;strong&gt;Axios&lt;/strong&gt; to interact with the backend API.&lt;/li&gt;

&lt;li&gt;Used &lt;strong&gt;Tailwind CSS&lt;/strong&gt; for styling and responsiveness.&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Adding Image Upload Feature
&lt;/h3&gt;

&lt;p&gt;I used &lt;strong&gt;Multer&lt;/strong&gt; on the backend for blog post images to handle file uploads.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set up Multer to store images in a folder and return the image path.&lt;/li&gt;
&lt;li&gt;Allowed users to upload images when creating blog posts.&lt;/li&gt;
&lt;li&gt;Displayed images dynamically on the frontend.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. Implementing Authentication
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Used &lt;strong&gt;JWT&lt;/strong&gt; tokens for authentication.&lt;/li&gt;
&lt;li&gt;Created a middleware to protect certain API routes.&lt;/li&gt;
&lt;li&gt;Stored JWT tokens in local storage to maintain user sessions.&lt;/li&gt;
&lt;li&gt;Redirected users dynamically based on their authentication status.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5. Deployment
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Deployed the &lt;strong&gt;backend&lt;/strong&gt; on &lt;strong&gt;Render&lt;/strong&gt; and &lt;strong&gt;frontend&lt;/strong&gt; on &lt;strong&gt;Vercel&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Configured CORS for secure API calls.&lt;/li&gt;
&lt;li&gt;Connected the frontend and backend with the correct API URLs.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Challenges I Faced
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;CORS Issues&lt;/strong&gt;: I had to configure CORS properly to allow frontend-backend communication.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JWT Token Expiry&lt;/strong&gt;: Initially, tokens were not expiring properly, leading to authentication issues.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Database Connectivity Errors&lt;/strong&gt;: Faced some issues with MongoDB Atlas connections, which I solved by ensuring proper connection string usage.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Lessons Learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Understanding authentication flow (JWT, password hashing, protected routes) was crucial.&lt;/li&gt;
&lt;li&gt;Breaking down the project into smaller tasks helped in better implementation.&lt;/li&gt;
&lt;li&gt;Debugging errors using console logs and Postman made API testing easier.&lt;/li&gt;
&lt;li&gt;Deployment issues taught me the importance of environment variables and CORS settings.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Building this blog website using the &lt;strong&gt;MERN stack&lt;/strong&gt; was a great learning experience. It gave me hands-on experience with full-stack development, authentication, and deployment. If you’re looking to build your first full-stack project, I highly recommend starting with something simple like a blog website.&lt;/p&gt;

&lt;p&gt;If you have any questions or need guidance, feel free to connect with me!&lt;/p&gt;




</description>
      <category>webdev</category>
      <category>mern</category>
      <category>beginners</category>
      <category>learning</category>
    </item>
    <item>
      <title>Data Structures Level Up: Conquer Advanced Concepts Without Losing Your Mind</title>
      <dc:creator>Hardik Gayner </dc:creator>
      <pubDate>Sat, 25 Jan 2025 07:19:53 +0000</pubDate>
      <link>https://dev.to/imhardik/data-structures-level-up-conquer-advanced-concepts-without-losing-your-mind-4a9f</link>
      <guid>https://dev.to/imhardik/data-structures-level-up-conquer-advanced-concepts-without-losing-your-mind-4a9f</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;“Data structures are like tools in a toolbox—master the advanced ones, and you’ll be building solutions that others can only dream of. Just remember, even the best carpenter starts with a few bent nails.” - &lt;strong&gt;&lt;a href="https://dev.to/imhardik"&gt;Hardik Gayner&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, you’ve decided to dive into advanced data structures, huh? Congratulations! You’re either a masochist or someone who genuinely enjoys the challenge of bending your brain into new shapes. Either way, let’s embark on this journey together, and I promise, we’ll keep the tears to a minimum (or at least try).&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Step 1: Why Do You Even Need This?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Before you bury yourself under heaps of trees, heaps, and graphs, ask yourself, &lt;em&gt;why am I doing this?&lt;/em&gt; If your answer is “to crack coding interviews,” “to become a data structure ninja,” or “to impress my future self,” then great! If it’s “because everyone else is doing it,” stop. Life is short; go learn macramé instead.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Step 2: Start with the Basics (Or Else!)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;You can’t build a skyscraper on sand, and you can’t tackle advanced data structures without solid basics. Brush up on:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Arrays (your childhood friends)
&lt;/li&gt;
&lt;li&gt;Linked Lists (messy but lovable)
&lt;/li&gt;
&lt;li&gt;Stacks &amp;amp; Queues (the introverts of DSA)
&lt;/li&gt;
&lt;li&gt;Trees (more branches than your family WhatsApp group)
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you still call a binary tree a “fancy upside-down umbrella,” spend some time here. Don’t worry, no judgment... much.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Step 3: The Hall of Fame Structures&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Advanced data structures sound terrifying until you realize they’re just data with a bit more drama. Here’s a lineup of the stars:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Segment Trees:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
For when you want to query and update an array so fast, it’ll feel like you cheated. Think of them as the snobby but efficient librarian of arrays.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fenwick Trees (Binary Indexed Trees):&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
They do a similar job but with fewer branches. They’re like segment trees’ cooler cousin—less dramatic but equally useful.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Tries (Prefix Trees):&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
The one-stop shop for searching strings. Want to autocomplete “I’m bored, how to study DSA” to “I’m bored, how to master tries”? This is your guy.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Disjoint Set Union (Union-Find):&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Ever been at a family reunion trying to figure out who’s related to whom? DSU is like that, except it actually works.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Graph Algorithms:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
DFS, BFS, Dijkstra, Kruskal—sounds like names of villains in a spy movie, but these are your go-to tools for navigating advanced structures.  &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Step 4: Resources (Because Google Alone Isn’t Enough)&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Books:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Introduction to Algorithms&lt;/em&gt; (a.k.a. CLRS): It’s not light reading, but neither is "Game of Thrones." Stick with it.
&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Competitive Programmer’s Handbook:&lt;/em&gt; Free and fabulous.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Videos:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Abdul Bari’s YouTube series: He explains things so well, you’ll want to write him a thank-you note.
&lt;/li&gt;
&lt;li&gt;Errichto’s Competitive Programming series: Pure gold for graph geeks.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Practice Platforms:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;LeetCode: The buffet of data structure problems.
&lt;/li&gt;
&lt;li&gt;HackerRank: Good for structured learning.
&lt;/li&gt;
&lt;li&gt;Codeforces: For when you’re ready to battle like a gladiator.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Step 5: Practice Like Your Keyboard Depends on It&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Start with &lt;strong&gt;easy problems&lt;/strong&gt; to warm up.
&lt;/li&gt;
&lt;li&gt;Move to &lt;strong&gt;medium problems&lt;/strong&gt; once you stop crying over the easy ones.
&lt;/li&gt;
&lt;li&gt;Attempt &lt;strong&gt;hard problems&lt;/strong&gt; only after establishing a meditation routine.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If a problem makes no sense, try solving it with brute force first. Then optimize. (Pro tip: If optimization feels impossible, blame the problem setter and move on.)  &lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Step 6: Debugging: The Real Nightmare&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;You will write code that doesn’t work. This is a fact of life, like gravity or people cutting you off in traffic.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Print statements are your best friend.&lt;/strong&gt; Use them generously.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rubber duck debugging:&lt;/strong&gt; Explain your code to a rubber duck. If you don’t have one, use your dog, plant, or imaginary friend.
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Step 7: Make It Fun&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Gamify the process: Treat every problem solved as an XP point.
&lt;/li&gt;
&lt;li&gt;Form study groups: Misery loves company.
&lt;/li&gt;
&lt;li&gt;Reward yourself: Solved a segment tree problem? Eat cake. (You deserve it.)
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Step 8: Know When to Quit&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Sometimes, the best way to solve a problem is to not solve it—&lt;em&gt;at least not immediately.&lt;/em&gt; Take a break, walk, or binge-watch a series. Just don’t quit altogether. (Advanced data structures are like dark chocolate—bitter at first but worth the effort.)&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Step 9: Stay Motivated&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Remember, every programmer you admire once struggled with this stuff too. They cried over heap implementations, cursed at graphs, and Googled “how does a trie work” just like you.&lt;/p&gt;




&lt;h3&gt;
  
  
  Final Thoughts
&lt;/h3&gt;

&lt;p&gt;Advanced data structures are tough but not impossible. They’re like taming a dragon—daunting at first, but once you master them, you’ll feel invincible. So, saddle up, grab your keyboard, and prepare to conquer. And remember: when in doubt, blame the compiler. Happy coding! 🚀&lt;/p&gt;

</description>
      <category>dsa</category>
      <category>programming</category>
      <category>career</category>
      <category>learning</category>
    </item>
    <item>
      <title>How to Study for DSA and Development Side by Side</title>
      <dc:creator>Hardik Gayner </dc:creator>
      <pubDate>Fri, 24 Jan 2025 13:19:30 +0000</pubDate>
      <link>https://dev.to/imhardik/how-to-study-for-dsa-and-development-side-by-side-mlm</link>
      <guid>https://dev.to/imhardik/how-to-study-for-dsa-and-development-side-by-side-mlm</guid>
      <description>&lt;p&gt;Balancing Data Structures and Algorithms (DSA) with Development skills can seem daunting, especially when both require a significant amount of focus and practice. However, with a structured approach and the right mindset, it is possible to study both concurrently and make steady progress in each field. Here's a guide on how to efficiently balance DSA and development in your study routine.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. &lt;strong&gt;Set Clear Goals for Both Areas&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Before diving into your studies, it’s crucial to understand what you aim to achieve in both DSA and Development. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;For DSA:&lt;/strong&gt; Your goal is to become proficient in solving algorithmic problems, understanding time and space complexities, and mastering problem-solving techniques.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;For Development:&lt;/strong&gt; Your goal is to build strong coding practices, learn how to work with frameworks, databases, and create scalable applications.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These two areas complement each other, so having clarity on the big picture will help you stay motivated and track progress effectively.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. &lt;strong&gt;Create a Balanced Schedule&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;To manage both, consistency is key. Here’s how you can structure your daily study routine:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Morning Session (1.5 hours):&lt;/strong&gt; Dedicate time to DSA. In the morning, your mind is fresh, and you can focus better on solving complex algorithmic problems. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start by solving problems of varying difficulty levels (easy, medium, hard) from platforms like LeetCode, HackerRank, and GeeksforGeeks.&lt;/li&gt;
&lt;li&gt;Focus on one or two topics per week, such as arrays, dynamic programming, or trees, so you can get deep into the subject.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Afternoon Session (2 hours):&lt;/strong&gt; Shift focus to development. This is a good time to apply the concepts you've learned through hands-on projects.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Work on building real-world applications using technologies like Node.js, Express, or MongoDB.&lt;/li&gt;
&lt;li&gt;Dedicate time to learning the underlying principles of the technologies you are using.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;strong&gt;Evening Session (1 hour):&lt;/strong&gt; Review and consolidate your learning. Take time to revisit the DSA problems you found difficult and analyze solutions. For development, you can spend time reading documentation, exploring new libraries, or working on debugging.&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;h4&gt;
  
  
  3. &lt;strong&gt;Use a Time-Blocking Technique&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;For efficient study, break down your study time into focused blocks, known as time-blocking. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;45-minute block for DSA:&lt;/strong&gt; Focus entirely on solving DSA problems. Avoid distractions and stay concentrated.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;15-minute break:&lt;/strong&gt; Rest and recharge before jumping into development work.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;45-minute block for Development:&lt;/strong&gt; Work on coding projects, exploring new concepts, or debugging.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After two or three blocks, take a longer break of 30 minutes to relax and reset.&lt;/p&gt;

&lt;h4&gt;
  
  
  4. &lt;strong&gt;Prioritize Depth Over Breadth&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Trying to learn everything at once can lead to burnout and confusion. Instead, choose one topic at a time in both DSA and development, and master it before moving on to the next. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;DSA:&lt;/strong&gt; If you're learning dynamic programming, dedicate an entire week or more to solving dynamic programming problems.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Development:&lt;/strong&gt; If you’re learning a new framework like Express.js, spend the next few days building small apps using Express before moving on to more advanced concepts like middleware or security.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This approach helps avoid confusion and ensures that you gain in-depth knowledge before moving on.&lt;/p&gt;

&lt;h4&gt;
  
  
  5. &lt;strong&gt;Link DSA with Development&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Use DSA to enhance your development skills and vice versa. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When building an application, think about the algorithms and data structures you might need to optimize your code (like using hash maps for fast lookups or trees for hierarchical data).&lt;/li&gt;
&lt;li&gt;When solving DSA problems, consider how you would implement them in a real-world application (e.g., using stacks in an undo/redo feature or using a graph algorithm to find the shortest path in a navigation system).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By interconnecting both, you strengthen your problem-solving abilities while gaining practical development skills.&lt;/p&gt;

&lt;h4&gt;
  
  
  6. &lt;strong&gt;Work on Projects Simultaneously&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Building real projects while studying DSA will keep you motivated and provide a tangible way to apply your learning. Here’s how:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Personal Projects:&lt;/strong&gt; Start a simple development project that involves the use of algorithms you’ve learned in DSA. For instance, you could build a weather application (using APIs) and optimize it with algorithms such as sorting or searching.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Competitive Programming:&lt;/strong&gt; Participate in coding challenges while developing your own projects. Both will enhance your problem-solving skills and real-world coding experience.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  7. &lt;strong&gt;Stay Consistent but Flexible&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Consistency is essential, but it’s also important to stay flexible. If you find a particular DSA topic hard or development task overwhelming, don’t hesitate to adjust your schedule. Take breaks or switch focus temporarily to refresh your mind. &lt;/p&gt;

&lt;h4&gt;
  
  
  8. &lt;strong&gt;Join Communities and Learn from Others&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Engaging with communities like Stack Overflow, GitHub, or Reddit can be incredibly helpful in your journey. Not only will you get help when you're stuck, but interacting with others will also expose you to new concepts and best practices that you might not have encountered.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;For DSA:&lt;/strong&gt; Participate in forums like Codeforces or LeetCode Discuss.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;For Development:&lt;/strong&gt; Join communities like GitHub, Dev.to, or attend local meetups.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  9. &lt;strong&gt;Monitor Your Progress&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Keep track of your progress in both DSA and development. Use tools like a progress journal, or simple tracking sheets, to note down your learning milestones, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Number of DSA problems solved.&lt;/li&gt;
&lt;li&gt;Number of projects completed.&lt;/li&gt;
&lt;li&gt;Technologies learned or enhanced.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This will help you visualize your progress and stay motivated.&lt;/p&gt;

&lt;h4&gt;
  
  
  10. &lt;strong&gt;Seek Feedback&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Always seek feedback on both your DSA solutions and development projects. In DSA, feedback helps improve your approach to solving problems efficiently. In development, constructive criticism from others (mentors, peers, or online communities) will guide you in refining your coding practices.&lt;/p&gt;




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

&lt;p&gt;Studying DSA and development side by side requires discipline, strategic planning, and consistent effort. By balancing your study time, integrating both areas, and applying your knowledge through real-world projects, you can efficiently become proficient in both. The key is to stay focused, adjust as needed, and enjoy the learning process.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>dsa</category>
      <category>java</category>
    </item>
    <item>
      <title>From Arrays to APIs: My (Mis)Adventures in Web Development</title>
      <dc:creator>Hardik Gayner </dc:creator>
      <pubDate>Sat, 18 Jan 2025 13:25:05 +0000</pubDate>
      <link>https://dev.to/imhardik/from-arrays-to-apis-my-misadventures-in-web-development-45f8</link>
      <guid>https://dev.to/imhardik/from-arrays-to-apis-my-misadventures-in-web-development-45f8</guid>
      <description>&lt;p&gt;Once upon a time in a not-so-distant past, a curious BCA student named Hardik (yep, that's me!) set out on a journey to conquer the vast and wild land of Web Development. Armed with nothing but a laptop, an unholy obsession with LeetCode streaks, and a mild fear of semicolons, I dove headfirst into the world of backend development. Spoiler alert: It’s been a ride.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;The Origin Story&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;I started my coding career like every other confused student—Googling "What is programming?" and being traumatized by the sight of my first &lt;code&gt;Hello World&lt;/code&gt;. Fast forward to today, I can confidently say: &lt;strong&gt;I still Google stuff, but at least now I know what to Google.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The real spark for web development ignited when I realized the backend world was the perfect mix of logic, creativity, and the occasional debugging-induced existential crisis. So, I rolled up my sleeves and got friendly with &lt;strong&gt;Node.js, Express.js, SQL, MongoDB&lt;/strong&gt;, and other buzzwords recruiters love to hear.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;A DSA Dev Who Dabbles in Databases&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Before we go any further, let me clarify: I’m not just a &lt;em&gt;developer&lt;/em&gt;—I’m also a &lt;em&gt;DSA survivor&lt;/em&gt;. Over the past months, I’ve solved 100+ LeetCode problems, earned a 50-day streak, and even cracked a couple of "hard" questions. Each problem taught me valuable lessons, like how to handle edge cases...and emotional breakdowns.&lt;/p&gt;

&lt;p&gt;But let’s be real: The real magic happens when you combine DSA with development. My favorite phrase these days? &lt;strong&gt;“O(1) or bust!”&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;The Project Diaries&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;After months of honing my skills, I decided it was time to build something more than just “another to-do app” (no offense, to-do lists). Thus, &lt;strong&gt;TravelBuddy&lt;/strong&gt; was born—my first big web project. Imagine a platform where travelers can find companions to share costs like food, accommodation, and even terrible road trip playlists. Built using &lt;strong&gt;ExpressJS, MongoDB, and EJS&lt;/strong&gt;, this project is my ode to wanderlust and problem-solving.&lt;/p&gt;

&lt;p&gt;And that’s not all. I’ve also brainstormed a &lt;em&gt;next-level&lt;/em&gt; idea: a website where you challenge your friends with coding problems and give hints at a point cost. Think of it as LeetCode meets Monopoly—except the fights are over code, not rent on Boardwalk.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Learning Curve or Roller Coaster?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Let’s talk about the journey. Web development has been a mix of moments where I felt like a wizard casting spells (&lt;code&gt;console.log(‘It works!’)&lt;/code&gt;) and moments where I stared blankly at my screen, wondering why the CSS margin was ruining my life.  &lt;/p&gt;

&lt;p&gt;Every bug is like a gym trainer for your brain—it hurts, but it makes you stronger. For example, did you know that forgetting to return a promise in JavaScript can wreck your whole app? Neither did I...until I did.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;The Llama Drama&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Recently, I’ve been exploring the world of LLMs (Large Language Models). The goal? To create a personal project where users can input their LeetCode stats and get personalized suggestions for problems to solve. Picture an AI-powered coach who’s brutally honest about your weaknesses but still wants you to win. I’m still figuring it out, but hey, even AI had to start somewhere.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;What’s Next?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;As of now, I’m focused on mastering backend development, exploring full-stack projects, and maybe applying for some shiny internships at Google, Amazon, and Microsoft. Oh, and cracking jokes on LinkedIn. Because what’s life without a little humor?&lt;/p&gt;

&lt;p&gt;I’ve also got a backup plan: NIMCET prep for an MCA. Because hey, who doesn’t love the thrill of having &lt;strong&gt;two career paths&lt;/strong&gt; and &lt;strong&gt;double the anxiety&lt;/strong&gt;?&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Final Thoughts&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To sum it up, my web dev journey has been a beautiful mess—a mix of structured APIs and chaotic semicolons, late-night coding sessions, and the occasional "Let’s burn it all down and start fresh." But that’s the beauty of it, isn’t it?  &lt;/p&gt;

&lt;p&gt;If you’re reading this and thinking about starting your web dev journey, remember this: &lt;strong&gt;Break your code, not your spirit.&lt;/strong&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;P.S.&lt;/strong&gt; To anyone hiring: I come with a side of Node.js expertise, MongoDB know-how, and a willingness to debug your code &lt;em&gt;and&lt;/em&gt; your life decisions. DM me. 😉&lt;/p&gt;




</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
