<?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: Ibrahim Ayandiran</title>
    <description>The latest articles on DEV Community by Ibrahim Ayandiran (@iam-phenomenal).</description>
    <link>https://dev.to/iam-phenomenal</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%2F1010387%2Fefea6aaf-1e10-474a-86a0-207ffe756e3b.png</url>
      <title>DEV Community: Ibrahim Ayandiran</title>
      <link>https://dev.to/iam-phenomenal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/iam-phenomenal"/>
    <language>en</language>
    <item>
      <title>Part 1: Mastering Modules in Node.js</title>
      <dc:creator>Ibrahim Ayandiran</dc:creator>
      <pubDate>Wed, 03 Jul 2024 18:40:35 +0000</pubDate>
      <link>https://dev.to/iam-phenomenal/part-1-mastering-modules-in-nodejs-3mm5</link>
      <guid>https://dev.to/iam-phenomenal/part-1-mastering-modules-in-nodejs-3mm5</guid>
      <description>&lt;p&gt;&lt;strong&gt;In our digital world, everything around us is part of a vast tech ecosystem with software at its core.&lt;/strong&gt; Over the years, a plethora of programming languages have been created to develop software. Some are problem-specific, some are multi-functional, and others have evolved from being problem-specific to multi-functional. JavaScript, at its genesis, was a programming language designed to bring interactivity to web applications. It's come a long way since then, and JavaScript now offers much more.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Node.js is a JavaScript runtime environment built on the Chrome V8 engine, allowing execution of JavaScript code outside web browsers.&lt;/strong&gt; One of its core strengths lies in its modular structure. By the end of this article, you will have a clear understanding of what modules are, what problem they are trying to solve and how to use them.&lt;/p&gt;

&lt;h4&gt;
  
  
  Understanding Modules Through DRY and SRP
&lt;/h4&gt;

&lt;p&gt;If you're familiar with the software development principles of DRY (Don't Repeat Yourself) and SRP (Single Responsibility Principle), then you've grasped the core problems that modules address. Modules are blocks of code that encapsulate related functionalities, making them reusable and maintainable. A well-written module adheres to both DRY and SRP principles, offering several advantages:&lt;/p&gt;

&lt;h5&gt;
  
  
  Code Reusability:
&lt;/h5&gt;

&lt;p&gt;Instead of duplicating code across your application, you can create a module and reuse it wherever needed. This reduces redundancy and minimizes errors.&lt;/p&gt;

&lt;h5&gt;
  
  
  Maintenance:
&lt;/h5&gt;

&lt;p&gt;Updating the logic becomes simpler and less error-prone. With modules, you only need to change the code in one place (the module itself) rather than modify it in multiple locations throughout your application.&lt;/p&gt;

&lt;h5&gt;
  
  
  Separation of Concerns:
&lt;/h5&gt;

&lt;p&gt;Modules allow developers to break down complex applications into smaller, manageable parts with focused functionalities. This improves code readability and fosters better collaboration within development teams, as developers can work on specific modules without worrying about unintended side effects in other areas of the application.&lt;/p&gt;

&lt;h5&gt;
  
  
  Namespace Management:
&lt;/h5&gt;

&lt;p&gt;Modules prevent naming conflicts. Variables and functions declared within a module are local to that module, avoiding clashes with global variables or variables used in other modules. to that module, avoiding clashes with global variables or variables used in other modules.&lt;/p&gt;

&lt;h4&gt;
  
  
  Types of Modules:
&lt;/h4&gt;

&lt;p&gt;In Node.JS there are three(3) types of modules, these are;&lt;/p&gt;

&lt;h5&gt;
  
  
  Core/Built-in Modules:
&lt;/h5&gt;

&lt;p&gt;These are built-in modules that come pre-installed with Node.js, providing essential functionalities like file system access (&lt;code&gt;fs&lt;/code&gt;), HTTP communication (&lt;code&gt;http&lt;/code&gt;), and path manipulation (&lt;code&gt;path&lt;/code&gt;).&lt;/p&gt;

&lt;h5&gt;
  
  
  Local/Custom Modules:
&lt;/h5&gt;

&lt;p&gt;These are modules you define within your application. They can be imported across different parts of your project extending its functionalities.&lt;/p&gt;

&lt;h5&gt;
  
  
  Third-Party Modules:
&lt;/h5&gt;

&lt;p&gt;These are the third-party modules you import using the &lt;code&gt;npm install&lt;/code&gt; or &lt;code&gt;yarn add&lt;/code&gt; command. These modules are developed by other developers and published in the software registry.&lt;/p&gt;

&lt;h4&gt;
  
  
  How to create Local/Custom Modules:
&lt;/h4&gt;

&lt;p&gt;Depending on your module syntax, creating a module in Node.js can be done either of the ways listed below:&lt;/p&gt;

&lt;h5&gt;
  
  
  CJS (Common JavaScript):
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Define code block 
function add(arg1, arg2) {
    return arg1 + arg2;
}

// Export code block
module.exports = add;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Define code block
class MathHelper {
    add(arg1, arg2) {
        return arg1 + arg2
    }
}
module.exports = MathHelper
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  ES6 (ECMAScript 2015):
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function add(arg1, arg2) {
    return arg1 + arg2;
}

// Export code block
export { add };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export function add(arg1, arg2) {
    return arg1 + arg2;
}
`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MathHelper {
    add(arg1, arg2) {
        return arg1 + arg2
    }
}
// Export code block
export default add;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Importing Modules in Node.js
&lt;/h4&gt;

&lt;p&gt;Despite the three different types of modules in Node.js (core, local, and third-party), the import process remains consistent. However, the specific syntax you use might differ depending on your chosen module syntax style.&lt;/p&gt;

&lt;h5&gt;
  
  
  CJS (Common JavaScript):
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Built-in/Core Module
const http = require("http");

// Custom/Local Module 
const add = require("./mathUtils");

// Third-Party Module
const express = require("express")

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

&lt;/div&gt;



&lt;h5&gt;
  
  
  ES6 (ECMAScript 2015):
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Built-in/Core Module
import http from "http";

// Custom/Local Module 
import add from "./mathUtils";

// Third-Party Module
import express from "express"

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Conclusion
&lt;/h4&gt;

&lt;p&gt;In this first part of our series on Node.js modules, we unpacked the essentials. We explored how modules promote code reusability, maintainability, and separation of concerns—the cornerstones of clean code. We also covered the different types of modules available: core modules, custom local modules you define within your project, and the vast ecosystem of third-party modules accessible through npm.&lt;/p&gt;

&lt;p&gt;Stay tuned for part two, where we'll delve deeper into the technical aspects. We'll explore module wrappers, their role in providing private scope and caching, and how they differ from Immediately Invoked Function Expressions (IIFEs). We'll also discuss module caching in detail, explaining how Node.js optimizes performance by storing the results of required modules. &lt;br&gt;
For further reading check out the &lt;a href="https://nodejs.org/api/modules.html"&gt;Official Node.js Documentation on Modules&lt;/a&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>npm</category>
      <category>javascript</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Part 1: Mastering Modules in Node.js</title>
      <dc:creator>Ibrahim Ayandiran</dc:creator>
      <pubDate>Wed, 03 Jul 2024 18:40:34 +0000</pubDate>
      <link>https://dev.to/iam-phenomenal/part-1-mastering-modules-in-nodejs-1kg9</link>
      <guid>https://dev.to/iam-phenomenal/part-1-mastering-modules-in-nodejs-1kg9</guid>
      <description>&lt;p&gt;&lt;strong&gt;In our digital world, everything around us is part of a vast tech ecosystem with software at its core.&lt;/strong&gt; Over the years, a plethora of programming languages have been created to develop software. Some are problem-specific, some are multi-functional, and others have evolved from being problem-specific to multi-functional. JavaScript, at its genesis, was a programming language designed to bring interactivity to web applications. It's come a long way since then, and JavaScript now offers much more.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Node.js is a JavaScript runtime environment built on the Chrome V8 engine, allowing execution of JavaScript code outside web browsers.&lt;/strong&gt; One of its core strengths lies in its modular structure. By the end of this article, you will have a clear understanding of what modules are, what problem they are trying to solve and how to use them.&lt;/p&gt;

&lt;h4&gt;
  
  
  Understanding Modules Through DRY and SRP
&lt;/h4&gt;

&lt;p&gt;If you're familiar with the software development principles of DRY (Don't Repeat Yourself) and SRP (Single Responsibility Principle), then you've grasped the core problems that modules address. Modules are blocks of code that encapsulate related functionalities, making them reusable and maintainable. A well-written module adheres to both DRY and SRP principles, offering several advantages:&lt;/p&gt;

&lt;h5&gt;
  
  
  Code Reusability:
&lt;/h5&gt;

&lt;p&gt;Instead of duplicating code across your application, you can create a module and reuse it wherever needed. This reduces redundancy and minimizes errors.&lt;/p&gt;

&lt;h5&gt;
  
  
  Maintenance:
&lt;/h5&gt;

&lt;p&gt;Updating the logic becomes simpler and less error-prone. With modules, you only need to change the code in one place (the module itself) rather than modify it in multiple locations throughout your application.&lt;/p&gt;

&lt;h5&gt;
  
  
  Separation of Concerns:
&lt;/h5&gt;

&lt;p&gt;Modules allow developers to break down complex applications into smaller, manageable parts with focused functionalities. This improves code readability and fosters better collaboration within development teams, as developers can work on specific modules without worrying about unintended side effects in other areas of the application.&lt;/p&gt;

&lt;h5&gt;
  
  
  Namespace Management:
&lt;/h5&gt;

&lt;p&gt;Modules prevent naming conflicts. Variables and functions declared within a module are local to that module, avoiding clashes with global variables or variables used in other modules. to that module, avoiding clashes with global variables or variables used in other modules.&lt;/p&gt;

&lt;h4&gt;
  
  
  Types of Modules:
&lt;/h4&gt;

&lt;p&gt;In Node.JS there are three(3) types of modules, these are;&lt;/p&gt;

&lt;h5&gt;
  
  
  Core/Built-in Modules:
&lt;/h5&gt;

&lt;p&gt;These are built-in modules that come pre-installed with Node.js, providing essential functionalities like file system access (&lt;code&gt;fs&lt;/code&gt;), HTTP communication (&lt;code&gt;http&lt;/code&gt;), and path manipulation (&lt;code&gt;path&lt;/code&gt;).&lt;/p&gt;

&lt;h5&gt;
  
  
  Local/Custom Modules:
&lt;/h5&gt;

&lt;p&gt;These are modules you define within your application. They can be imported across different parts of your project extending its functionalities.&lt;/p&gt;

&lt;h5&gt;
  
  
  Third-Party Modules:
&lt;/h5&gt;

&lt;p&gt;These are the third-party modules you import using the &lt;code&gt;npm install&lt;/code&gt; or &lt;code&gt;yarn add&lt;/code&gt; command. These modules are developed by other developers and published in the software registry.&lt;/p&gt;

&lt;h4&gt;
  
  
  How to create Local/Custom Modules:
&lt;/h4&gt;

&lt;p&gt;Depending on your module syntax, creating a module in Node.js can be done either of the ways listed below:&lt;/p&gt;

&lt;h5&gt;
  
  
  CJS (Common JavaScript):
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Define code block 
function add(arg1, arg2) {
    return arg1 + arg2;
}

// Export code block
module.exports = add;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Define code block
class MathHelper {
    add(arg1, arg2) {
        return arg1 + arg2
    }
}
module.exports = MathHelper
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  ES6 (ECMAScript 2015):
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function add(arg1, arg2) {
    return arg1 + arg2;
}

// Export code block
export { add };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export function add(arg1, arg2) {
    return arg1 + arg2;
}
`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MathHelper {
    add(arg1, arg2) {
        return arg1 + arg2
    }
}
// Export code block
export default add;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Importing Modules in Node.js
&lt;/h4&gt;

&lt;p&gt;Despite the three different types of modules in Node.js (core, local, and third-party), the import process remains consistent. However, the specific syntax you use might differ depending on your chosen module syntax style.&lt;/p&gt;

&lt;h5&gt;
  
  
  CJS (Common JavaScript):
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Built-in/Core Module
const http = require("http");

// Custom/Local Module 
const add = require("./mathUtils");

// Third-Party Module
const express = require("express")

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

&lt;/div&gt;



&lt;h5&gt;
  
  
  ES6 (ECMAScript 2015):
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Built-in/Core Module
import http from "http";

// Custom/Local Module 
import add from "./mathUtils";

// Third-Party Module
import express from "express"

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Conclusion
&lt;/h4&gt;

&lt;p&gt;In this first part of our series on Node.js modules, we unpacked the essentials. We explored how modules promote code reusability, maintainability, and separation of concerns—the cornerstones of clean code. We also covered the different types of modules available: core modules, custom local modules you define within your project, and the vast ecosystem of third-party modules accessible through npm.&lt;/p&gt;

&lt;p&gt;Stay tuned for part two, where we'll delve deeper into the technical aspects. We'll explore module wrappers, their role in providing private scope and caching, and how they differ from Immediately Invoked Function Expressions (IIFEs). We'll also discuss module caching in detail, explaining how Node.js optimizes performance by storing the results of required modules. &lt;br&gt;
For further reading check out the &lt;a href="https://nodejs.org/api/modules.html"&gt;Official Node.js Documentation on Modules&lt;/a&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>npm</category>
      <category>javascript</category>
      <category>typescript</category>
    </item>
    <item>
      <title>The ORM vs. ODM Debate: A Node.js Backend Perspective</title>
      <dc:creator>Ibrahim Ayandiran</dc:creator>
      <pubDate>Mon, 13 May 2024 17:37:32 +0000</pubDate>
      <link>https://dev.to/iam-phenomenal/the-orm-vs-odm-debate-a-nodejs-backend-perspective-3pa0</link>
      <guid>https://dev.to/iam-phenomenal/the-orm-vs-odm-debate-a-nodejs-backend-perspective-3pa0</guid>
      <description>&lt;p&gt;Imagine reusing a proven approach for a new project, only to hit a wall. That's exactly what happened to me as a Node.js developer. I was building a MongoDB app, but I tried to force-fit Prisma (an ORM) because of it similarity with a previous PostgreSQL project. Big mistake! Prisma's MongoDB support limited my options. This experience got me obsessed with understanding ORMs vs. ODMs (think Prisma vs. Mongoose). Now, I'm here to share what I learned about choosing the right tool for the database job!&lt;/p&gt;

&lt;p&gt;So, what exactly are ORMs and ODMs? Let's break it down. These are tools that act as a bridge between your code and your database, but they cater to different database types.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Database Bridge Builders: Understanding ORMs and ODMs
&lt;/h2&gt;

&lt;p&gt;As backend engineers, we juggle complex data interactions between our code and the database. However, writing raw SQL queries can be tedious and error-prone. That's where Object-Relational Mappers (ORMs) and Object-Document Mappers (ODMs) come in – they act as powerful bridges simplifying those interactions.&lt;/p&gt;

&lt;h3&gt;
  
  
  What's an ORM?
&lt;/h3&gt;

&lt;p&gt;Imagine our backend code as a well-structured shopping cart application. Products (data) are stored in a relational database (think of it as a giant online store with organized categories and tables). An ORM acts as a translator. It seamlessly converts the product objects (items in the cart) into SQL queries that the database understands. This lets us interact with the data using familiar object-oriented code instead of writing complex SQL statements from scratch.&lt;/p&gt;

&lt;h4&gt;
  
  
  How does an ORM help?
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Boost Efficiency&lt;/strong&gt;: Skip writing repetitive SQL queries and focus on building core functionalities using objects.&lt;br&gt;
&lt;strong&gt;Minimize Errors&lt;/strong&gt;: ORMs handle the translation, reducing the risk of typos in complex SQL commands.&lt;br&gt;
&lt;strong&gt;Maintainability Magic&lt;/strong&gt;: The code becomes clearer and easier to modify for future developers (or even our future selves!).&lt;/p&gt;

&lt;h3&gt;
  
  
  What's an ODM?
&lt;/h3&gt;

&lt;p&gt;Now, imagine building a dynamic social media application. User profiles (data) can have various elements like posts, photos, and connections – a flexible structure. That's where ODMs excel! They work with document databases (think of it as a social media platform where user profiles are stored as JSON documents with diverse formats). ODMs map our user objects in the code to these documents within the database, allowing for a more adaptable approach.&lt;/p&gt;

&lt;h4&gt;
  
  
  How does an ODM help?
&lt;/h4&gt;

&lt;p&gt;Embrace Flexibility: ODMs handle data with ever-changing structures, perfect for projects with evolving requirements.&lt;br&gt;
Simplify Queries: Use object-oriented syntax or the native query language for document databases – no more complex SQL headaches.&lt;br&gt;
Focus on the Logic: Spend less time wrestling with database specifics and more time crafting your application's core functionalities.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Key Distinctions: ORMs vs. ODMs
&lt;/h2&gt;

&lt;p&gt;While both ORMs and ODMs act as bridges between your code and database, they cater to fundamentally different database structures. Let's break it down in a table to see the key distinctions:&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%2Fg2tnx5zuik8o11olyxwy.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%2Fg2tnx5zuik8o11olyxwy.png" alt="Image description" width="618" height="355"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Similarities:
&lt;/h2&gt;

&lt;p&gt;Despite their differences, ORMs and ODMs share some key features that make them valuable tools for backend developers:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Object Mapping&lt;/strong&gt;: Both translate your code's objects (representing real-world entities) into the database's storage format.&lt;br&gt;
&lt;strong&gt;Abstraction Layer&lt;/strong&gt;: They act as a middle layer, simplifying data interaction by hiding the complexities of raw SQL queries.&lt;br&gt;
&lt;strong&gt;Reduced Boilerplate&lt;/strong&gt;: They eliminate the need for writing repetitive and error-prone SQL, allowing you to focus on core application logic.&lt;br&gt;
In the next section, we'll delve deeper into how to choose the right tool (ORM vs. ODM) based on your specific database needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choosing the Right Weapon: ORMs vs. ODMs for Your Database Needs
&lt;/h2&gt;

&lt;p&gt;We've explored the strengths of both ORMs and ODMs, but which one reigns supreme for your project? Choosing the right tool is critical for:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Performance&lt;/strong&gt;: ORMs excel in relational databases with complex queries, while ODMs shine in document databases with fast inserts/updates and flexible structures.&lt;br&gt;
&lt;strong&gt;Development Efficiency&lt;/strong&gt;: ORMs streamline complex relationships in relational databases, while ODMs simplify working with evolving data structures in document databases.&lt;br&gt;
&lt;strong&gt;Maintainability&lt;/strong&gt;: Well-suited ORMs or ODMs lead to cleaner, more maintainable code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion: Choosing Your Database Partner
&lt;/h2&gt;

&lt;p&gt;Understanding ORMs and ODMs equips you to make informed decisions for your Node.js projects. By considering factors like performance, development efficiency, and database type, you can choose the right tool for the job.&lt;/p&gt;

&lt;p&gt;Remember, ORMs excel in structured relational databases with complex queries, while ODMs shine in flexible document databases with ever-changing data. With this knowledge, you're prepared to conquer any database challenge your Node.js projects throw your way!&lt;/p&gt;

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