<?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: Yaser </title>
    <description>The latest articles on DEV Community by Yaser  (@yaser_ssh).</description>
    <link>https://dev.to/yaser_ssh</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%2F1868431%2F7aa71ea0-10cd-47b9-8851-139af67dbdfd.jpeg</url>
      <title>DEV Community: Yaser </title>
      <link>https://dev.to/yaser_ssh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yaser_ssh"/>
    <language>en</language>
    <item>
      <title>🎉 The High of Solving a Tough Problem</title>
      <dc:creator>Yaser </dc:creator>
      <pubDate>Sun, 29 Sep 2024 12:02:50 +0000</pubDate>
      <link>https://dev.to/yaser_ssh/the-high-of-solving-a-tough-problem-4i6j</link>
      <guid>https://dev.to/yaser_ssh/the-high-of-solving-a-tough-problem-4i6j</guid>
      <description>&lt;p&gt;You know that rush when you’ve been staring at your code for hours, refactoring a Node.js API, and finally everything clicks? That moment when the app works, the test passes, and you solve the problem?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;There’s nothing better&lt;/strong&gt; . &lt;/p&gt;

&lt;p&gt;It’s not just in coding either—whether it’s finishing a project, closing a deal, or hitting a personal goal, that sense of accomplishment is unbeatable.&lt;/p&gt;

&lt;p&gt;⚡️ Here’s the thing: it’s the struggle that makes the win worth it. That late-night bug you squashed at 2 AM? That’s where growth happens.&lt;/p&gt;

&lt;p&gt;So don’t fear the grind. Chase that feeling.&lt;/p&gt;

&lt;p&gt;💬 What’s the last problem you solved that gave you that rush?&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>opensource</category>
    </item>
    <item>
      <title>🧠 Mistakes Make You a Better Developer – Don’t Run from Them!</title>
      <dc:creator>Yaser </dc:creator>
      <pubDate>Wed, 25 Sep 2024 20:56:02 +0000</pubDate>
      <link>https://dev.to/yaser_ssh/mistakes-make-you-a-better-developer-dont-run-from-them-3ndl</link>
      <guid>https://dev.to/yaser_ssh/mistakes-make-you-a-better-developer-dont-run-from-them-3ndl</guid>
      <description>&lt;p&gt;Ever feel frustrated when you hit a roadblock or mess up your code? Good. That frustration means you’re growing. If you aren’t reviewing your mistakes, you’re missing out on the best part of the game: &lt;strong&gt;improvement&lt;/strong&gt; .&lt;/p&gt;

&lt;p&gt;🔍 Every bug you miss, every error in your logic is a lesson. Go back, analyze where you went wrong, and you’ll be that much sharper next time.&lt;/p&gt;

&lt;p&gt;The best devs aren’t the ones who never make mistakes; they’re the ones who &lt;strong&gt;learn from every single one&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;📈 Keep making mistakes, keep reviewing them, and you’ll notice—your skills level up fast.&lt;/p&gt;

&lt;p&gt;💬 What’s the biggest mistake you’ve learned from in coding? Drop it below!&lt;/p&gt;

</description>
      <category>programming</category>
      <category>beginners</category>
      <category>node</category>
      <category>career</category>
    </item>
    <item>
      <title>💡 How to Protect Your Node.js App from CSRF Attacks with csurf</title>
      <dc:creator>Yaser </dc:creator>
      <pubDate>Tue, 24 Sep 2024 13:05:49 +0000</pubDate>
      <link>https://dev.to/yaser_ssh/how-to-protect-your-nodejs-app-from-csrf-attacks-with-csurf-227k</link>
      <guid>https://dev.to/yaser_ssh/how-to-protect-your-nodejs-app-from-csrf-attacks-with-csurf-227k</guid>
      <description>&lt;p&gt;As a developer, security should be your non-negotiable. One mistake with Cross-Site Request Forgery (CSRF), and you could be opening the door for malicious attacks. Here's how you can protect your Node.js app with a simple solution: the &lt;code&gt;csurf&lt;/code&gt;library.&lt;/p&gt;

&lt;p&gt;🚀 How to Use &lt;code&gt;csurf&lt;/code&gt;in Your Node.js App Made Simple&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Install the csurf package --&amp;gt; &lt;code&gt;npm install csurf&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: Add it to your app &lt;em&gt;code in image&lt;/em&gt;&lt;br&gt;
First, make sure you're using sessions or cookies because CSRF tokens are stored in them.&lt;/p&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%2F0tg0586ac5q5k4748nfo.png" 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%2F0tg0586ac5q5k4748nfo.png" alt="adding csrf" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What does this do?&lt;/p&gt;

&lt;p&gt;1️⃣ Adds CSRF protection to your routes.&lt;br&gt;
2️⃣ Ensures that every form submission or request includes a CSRF token, so no external attacker can hijack the session.&lt;/p&gt;

&lt;p&gt;Why is this important?&lt;/p&gt;

&lt;p&gt;It ensures every request is legit. With just a few lines of code, you’re preventing attackers from tricking your users into making unintended requests. 💪&lt;/p&gt;

&lt;p&gt;Have you added CSRF protection to your apps yet? If not, now’s the time! 🚨&lt;/p&gt;

</description>
    </item>
    <item>
      <title>🚀 Why Work Volume is the Key to Success as a Developer 💻</title>
      <dc:creator>Yaser </dc:creator>
      <pubDate>Sat, 21 Sep 2024 10:44:21 +0000</pubDate>
      <link>https://dev.to/yaser_ssh/why-work-volume-is-the-key-to-success-as-a-developer-45e</link>
      <guid>https://dev.to/yaser_ssh/why-work-volume-is-the-key-to-success-as-a-developer-45e</guid>
      <description>&lt;p&gt;There’s a lot of talk these days about “working smarter, not harder.” But let’s be honest—when it comes to achieving real results, work volume matters.&lt;/p&gt;

&lt;p&gt;As a software developer, success doesn’t come from shortcuts or hacks. It comes from consistently putting in the hours and getting the reps in.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Here’s the reality:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The more you code, debug, and solve problems, the better you get. The faster you find bugs, the quicker you optimize your APIs, and the more intuitive your solutions become. It’s a compound effect, and it all starts with work volume.&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;Think about this&lt;/strong&gt;:
&lt;/h5&gt;

&lt;p&gt;➡ &lt;strong&gt;Building a Node.js microservice&lt;/strong&gt; isn’t something you master by spending 30 minutes a day. It’s those long, focused days where you’re knee-deep in middleware, struggling with database connections, and refactoring code that truly move you forward.&lt;/p&gt;

&lt;p&gt;➡ &lt;strong&gt;Debugging&lt;/strong&gt;? It’s not glamorous. It’s hours of grinding to trace that one elusive bug breaking your application—but those hours matter.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Why is work volume key?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;1️⃣ &lt;strong&gt;Repetition builds expertise&lt;/strong&gt;: The more hours you put into your craft, the better you become. There’s no substitute for raw experience.&lt;/p&gt;

&lt;p&gt;2️⃣ &lt;strong&gt;Solving complex problems takes time&lt;/strong&gt;: That feeling when you finally crack a Node.js memory leak after hours of investigation? That’s growth, and it only comes through sheer work volume.&lt;/p&gt;

&lt;p&gt;3️⃣ &lt;strong&gt;The grind pays off&lt;/strong&gt;: If you want to build scalable, efficient systems, you can’t half-ass it. It takes long hours spent understanding edge cases, performance bottlenecks, and real-world scenarios.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Here’s my point:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Hitting your goals as a software developer is directly related to how much time you’re willing to invest in the work. Whether it's grinding through tutorials or hacking away at code for hours—consistent work volume is the engine that drives your growth.&lt;/p&gt;

&lt;p&gt;Don't let anyone tell you otherwise—you can’t cheat the grind.&lt;/p&gt;

&lt;p&gt;How do you manage your work volume to hit your goals? Let me know your thoughts! 👇&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>programming</category>
      <category>career</category>
      <category>webdev</category>
    </item>
    <item>
      <title>💥 "Do not f*ing miss": The Mindset for Success in Programming and Beyond💥</title>
      <dc:creator>Yaser </dc:creator>
      <pubDate>Tue, 17 Sep 2024 19:48:28 +0000</pubDate>
      <link>https://dev.to/yaser_ssh/do-not-fing-miss-the-mindset-for-success-in-programming-and-beyond-1on4</link>
      <guid>https://dev.to/yaser_ssh/do-not-fing-miss-the-mindset-for-success-in-programming-and-beyond-1on4</guid>
      <description>&lt;p&gt;Whether you’re coding, starting a business, or pursuing any goal, there’s one golden rule made by Jordan Peters: Do not f*ing miss. What does that mean? It means that when you commit to something, you give it everything. No distractions. No half-effort. No quick breaks every 15 minutes. You focus, go deep, and execute with precision. 🎯&lt;/p&gt;

&lt;p&gt;Focus is Everything&lt;br&gt;
In today's world, distractions are everywhere. Whether it’s social media, notifications, it’s easy to lose track. But here’s the deal: your best work comes when you’re fully immersed. This is especially true in programming. As a backend developer, every detail matters, and distractions lead to bugs, inefficiency, and bad architecture.&lt;/p&gt;

&lt;p&gt;When you sit down to code, commit to deep, uninterrupted work. For example, if you’re building an API in Node.js, don’t just write code that “works.” Write code that scales, performs, and is maintainable.&lt;/p&gt;

&lt;p&gt;Deep Work in Programming: Example with Node.js&lt;br&gt;
Let’s say you’re tasked with creating an efficient API endpoint that handles thousands of requests per second. A distracted developer might just write a basic handler and move on. But a focused developer? They go deeper:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require('express');
const app = express();

// Basic route - A distracted dev might stop here
app.get('/data', async (req, res) =&amp;gt; {
  const data = await fetchData(); // fetchData might be slow, causing issues later
  res.json(data);
});

// Focused work: Caching for performance
const cache = new Map();
app.get('/data', async (req, res) =&amp;gt; {
  if (cache.has('data')) {
    return res.json(cache.get('data')); // Return from cache
  }
  const data = await fetchData();
  cache.set('data', data); // Cache the result
  res.json(data);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first version might work, but it could be inefficient when traffic increases. The second version, on the other hand, includes caching, preventing repeated database queries and improving performance. That’s the difference between just working and working effectively.&lt;/p&gt;

&lt;p&gt;Consistency and Volume: The Secret to Evolution&lt;br&gt;
Here’s the truth: Success isn’t about one perfect moment of brilliance. It’s about consistent effort and high volume of work over time. Whether you're coding every day, launching features, fixing bugs, or improving your skills, volume is the key to thrive. The more you build, test, and learn, the more you evolve.&lt;/p&gt;

&lt;p&gt;As backend developers, we don’t just solve problems; we prevent them. Writing tests, handling edge cases, optimizing performance – these are the things that separate good programmers from great ones.&lt;/p&gt;

&lt;p&gt;Take error handling, for example. A distracted dev might handle only the obvious errors, while a focused dev prepares for every possible failure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Distracted error handling
app.get('/data', async (req, res) =&amp;gt; {
  const data = await fetchData();
  res.json(data);
});

// Focused error handling
app.get('/data', async (req, res) =&amp;gt; {
  try {
    const data = await fetchData();
    res.json(data);
  } catch (error) {
    console.error('Error fetching data:', error);
    res.status(500).json({ error: 'Failed to fetch data' });
  }
});

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

&lt;/div&gt;



&lt;p&gt;When you focus deeply and put in the reps, you think beyond just the "happy path" and make your code more robust. The more code you write, the better you get at catching potential issues before they happen. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You actually have no idea how important work volume is in every damn aspect of your life.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Work Deep, Avoid Shallow&lt;br&gt;
Shallow work is easy: it’s the 5-minute email checks, quick Slack replies, or writing code that’s “good enough.” But shallow work won’t make you great. To truly excel, you need to dive deep. That means long, uninterrupted periods of work where you solve hard problems, learn new techniques, and build things that matter.&lt;/p&gt;

&lt;p&gt;Here’s a tip: Time-block your day. Dedicate 2-3 hours to deep coding sessions, no distractions, no interruptions. Whether you’re debugging a tricky issue or implementing a new feature, this is where the magic happens.&lt;/p&gt;

&lt;p&gt;Maximizing Effectiveness&lt;br&gt;
Being effective is not just about writing code fast. It’s about writing the right code. It’s about solving the right problems in the most efficient way possible. Here’s an example of working effectively in Node.js:&lt;/p&gt;

&lt;p&gt;You’re tasked with creating a real-time chat system. Sure, you could just use setTimeout to poll the server every few seconds. But is that effective? Not really. Instead, consider using WebSockets for real-time, bi-directional communication. This is what "not missing" looks like in programming:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const WebSocket = require('ws');
const server = new WebSocket.Server({ port: 8080 });

server.on('connection', (socket) =&amp;gt; {
  socket.on('message', (message) =&amp;gt; {
    console.log(`Received: ${message}`);
    // Broadcast the message to all connected clients
    server.clients.forEach(client =&amp;gt; {
      if (client.readyState === WebSocket.OPEN) {
        client.send(message);
      }
    });
  });

  socket.send('Welcome to the chat!');
});

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

&lt;/div&gt;



&lt;p&gt;This approach ensures a scalable, real-time solution instead of a quick and dirty hack.&lt;/p&gt;

&lt;p&gt;No Excuses, Just Execution&lt;br&gt;
At the end of the day, success in any field boils down to consistent execution and volume of effort. Whether you’re writing code, starting a business, or pursuing any other goal, it’s all about taking it seriously and putting in the hard work. No distractions. No shortcuts. Just deep, effective work, and doing it over and over.&lt;/p&gt;

&lt;p&gt;So, the next time you sit down to code, remember: Do not f*ing miss**. 💥 And above all, keep putting in the reps—because volume is the key to growth and evolution. 💪&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>productivity</category>
      <category>backend</category>
    </item>
    <item>
      <title>🌟 JWT auth made pretty pretty simple!</title>
      <dc:creator>Yaser </dc:creator>
      <pubDate>Thu, 12 Sep 2024 11:46:24 +0000</pubDate>
      <link>https://dev.to/yaser_ssh/jwt-auth-made-pretty-pretty-simple-226j</link>
      <guid>https://dev.to/yaser_ssh/jwt-auth-made-pretty-pretty-simple-226j</guid>
      <description>&lt;p&gt;If you're working with &lt;strong&gt;Node.js&lt;/strong&gt; and need to implement user authentication, &lt;strong&gt;JWT&lt;/strong&gt; is one of the most efficient ways to do it! Here's a super simple guide to get you started.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is JWT? 🤔
&lt;/h3&gt;

&lt;p&gt;JWT is a way to securely transmit information between the client and server as a token. It's commonly used for authentication, and the best part is, once a token is generated, you don’t need to store user data on the server — everything is inside the token itself.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to Implement JWT in Node.js 🚀
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Set up your Node.js project&lt;/strong&gt;:&lt;br&gt;
Install Express, JWT, and dotenv:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;express jsonwebtoken dotenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Create a registration and login system&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When a user registers or logs in, you generate a JWT token.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example of generating a JWT:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&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="s1"&gt;jsonwebtoken&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Here we generate the jwt token --&amp;gt; jwt.sign(payload, secretKey, modreOptions)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt; &lt;span class="o"&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="na"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;user1&lt;/span&gt;&lt;span class="dl"&gt;'&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="s1"&gt;1h&lt;/span&gt;&lt;span class="dl"&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;log&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;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Protect your routes with JWT&lt;/strong&gt;:&lt;br&gt;
Create a middleware to check if the JWT is valid before giving access to protected routes.&lt;/p&gt;

&lt;p&gt;Example middleware:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;
&lt;span class="c1"&gt;// /middleware/auth.js&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="s1"&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;function&lt;/span&gt; &lt;span class="nf"&gt;authMiddleware&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="nx"&gt;next&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;token&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="nf"&gt;header&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Authorization&lt;/span&gt;&lt;span class="dl"&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="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;token&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;401&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;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Access denied&lt;/span&gt;&lt;span class="dl"&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="c1"&gt;// Verify the token --&amp;gt; jwt.verify(tokenValue, secretKey)&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;verified&lt;/span&gt; &lt;span class="o"&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;verify&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="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="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="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;verified&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;next&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;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;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Invalid token&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;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Add the middleware function to your protected routes&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;
&lt;span class="c1"&gt;// Just pass the middleware (autMiddleware) as an argument&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;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&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;authMiddleware&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;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`Welcome &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="nx"&gt;username&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;span class="p"&gt;});&lt;/span&gt;

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

&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And that’s it! 🎉 With these few lines of code, you have JWT-based authentication set up in Node.js! 🚀&lt;/p&gt;

&lt;p&gt;💡 &lt;strong&gt;Bonus tip&lt;/strong&gt;: Always store your JWT secret in environment variables (&lt;code&gt;.env&lt;/code&gt;) to keep it safe, and set reasonable expiration times for tokens.&lt;/p&gt;




&lt;p&gt;Feel free to share this or try it yourself!  😊&lt;/p&gt;

&lt;h1&gt;
  
  
  Nodejs #JWT #Authentication #WebDevelopment #Backend #Security
&lt;/h1&gt;

</description>
    </item>
    <item>
      <title>🧑‍💻 Express.js Middleware and Asynchronous Operations</title>
      <dc:creator>Yaser </dc:creator>
      <pubDate>Thu, 12 Sep 2024 01:35:22 +0000</pubDate>
      <link>https://dev.to/yaser_ssh/expressjs-middleware-and-asynchronous-operations-21o8</link>
      <guid>https://dev.to/yaser_ssh/expressjs-middleware-and-asynchronous-operations-21o8</guid>
      <description>&lt;p&gt;I recently encountered a challenging issue in an Express.js application that involved using middleware to handle asynchronous operations and error handling. What do you think will happen?&lt;/p&gt;

&lt;p&gt;💡 Share your thoughts on what the console output will be.&lt;/p&gt;

&lt;h1&gt;
  
  
  ExpressJS #Middleware #AsynchronousOperations #ErrorHandling
&lt;/h1&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%2F34kthc545ldfyxatvwwm.jpg" 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%2F34kthc545ldfyxatvwwm.jpg" alt="Image description" width="555" height="590"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>🚀 Best Practices to Boost Your Node.js App Performance 🚀</title>
      <dc:creator>Yaser </dc:creator>
      <pubDate>Thu, 12 Sep 2024 01:34:14 +0000</pubDate>
      <link>https://dev.to/yaser_ssh/best-practices-to-boost-your-nodejs-app-performance-59m6</link>
      <guid>https://dev.to/yaser_ssh/best-practices-to-boost-your-nodejs-app-performance-59m6</guid>
      <description>&lt;p&gt;💡 Optimize Database Queries: Whether you’re using MongoDB, MySQL, or any other DB, optimize your queries! Use indexes and avoid fetching unnecessary data.&lt;/p&gt;

&lt;p&gt;🏎️ Leverage Caching: Improve speed and efficiency by implementing caching mechanisms such as Redis or in-memory cache. Store frequently accessed data to reduce reliance on repetitive DB calls.&lt;/p&gt;

&lt;p&gt;🛠️ Use Streams for Large Data: If you’re dealing with large files (like videos), use Node.js streams instead of loading everything into memory. It’s more efficient and faster!&lt;/p&gt;

&lt;p&gt;⚡ Cluster Your App: Node.js runs on a single thread by default, but you can use clustering to take advantage of multi-core processors. More cores = more power.&lt;/p&gt;

&lt;p&gt;🚨 Monitor and Fix Memory Leaks: Prevent app slowdowns or crashes by proactively monitoring and addressing memory leaks. Tools like clinic, node-memwatch, or heapdump can help detect and resolve these issues effectively. &lt;/p&gt;

&lt;p&gt;Implement these best practices to optimize your Node.js application's performance and ensure a seamless user experience! &lt;/p&gt;

&lt;h1&gt;
  
  
  NodeJS #AppDevelopment #PerformanceOptimization #TechTips
&lt;/h1&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>node</category>
    </item>
    <item>
      <title>💡 Design Patterns are Cool, But Language Features are Forever 💡</title>
      <dc:creator>Yaser </dc:creator>
      <pubDate>Thu, 12 Sep 2024 01:30:48 +0000</pubDate>
      <link>https://dev.to/yaser_ssh/design-patterns-are-cool-but-language-features-are-forever-5fd1</link>
      <guid>https://dev.to/yaser_ssh/design-patterns-are-cool-but-language-features-are-forever-5fd1</guid>
      <description>&lt;p&gt;Design patterns are one of those things that make us go, "Oh yeah, this solves a problem!" They can help tackle specific challenges, but sometimes people overcomplicate things by forcing patterns into every situation. On the flip side, you might be using a design pattern without even knowing it! 🎯&lt;/p&gt;

&lt;p&gt;Take the Visitor Pattern for example. It’s often used in object-oriented languages, and I remember being confused by it when I started. It felt like a lot of code for something I didn’t fully get. Later on, I came across pattern matching in languages like Rust and functional programming concepts, and things clicked. 🤯&lt;/p&gt;

&lt;p&gt;The cool thing? Modern JavaScript (and Node.js) has been evolving, and with features like destructuring, template literals, and switch pattern matching (coming soon), you might not even need some of these old-school patterns anymore! Features in the language are often better solutions because they reduce complexity, and make your code more readable and expressive.&lt;/p&gt;

&lt;p&gt;For example, in Node.js, you can use pattern matching with switch or destructuring objects to simplify complex decision-making, without diving into complex OOP-style patterns.&lt;/p&gt;

&lt;p&gt;So while design patterns can be useful, it’s always great to lean on the language's features when possible. Keep it simple, efficient, and readable! 🔥&lt;/p&gt;

&lt;h1&gt;
  
  
  JavaScript #Nodejs #DesignPatterns #WebDevelopment #CodingTips
&lt;/h1&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%2Ftvyn1rwpdnjvvyfridxk.jpg" 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%2Ftvyn1rwpdnjvvyfridxk.jpg" alt="Image description" width="504" height="263"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>node</category>
      <category>designpatterns</category>
    </item>
  </channel>
</rss>
