<?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: Musab</title>
    <description>The latest articles on DEV Community by Musab (@moshkh).</description>
    <link>https://dev.to/moshkh</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%2F782908%2Fb7fde45d-fef2-492e-aec5-637b5243b396.png</url>
      <title>DEV Community: Musab</title>
      <link>https://dev.to/moshkh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/moshkh"/>
    <language>en</language>
    <item>
      <title>Understanding Svelte: Setting Up Your Project and Mastering .svelte Files</title>
      <dc:creator>Musab</dc:creator>
      <pubDate>Sun, 21 Apr 2024 21:19:24 +0000</pubDate>
      <link>https://dev.to/moshkh/understanding-svelte-setting-up-your-project-and-mastering-svelte-files-22j8</link>
      <guid>https://dev.to/moshkh/understanding-svelte-setting-up-your-project-and-mastering-svelte-files-22j8</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;I’m very much in the midst of my Svelte knowledge refresh, and to share my learnings with you effectively it would be most prudent to start by walking through the setup of a Svelte project and understanding the role of a &lt;strong&gt;&lt;code&gt;.svelte&lt;/code&gt;&lt;/strong&gt; file - where the magic happens!&lt;/p&gt;

&lt;h2&gt;
  
  
  A word about SvelteKit…
&lt;/h2&gt;

&lt;p&gt;SvelteKit is the easiest way to start developing with Svelte. SvelteKit is a framework built on top of Svelte that simplifies the development of fast and interactive web applications. It provides tools and features for managing pages, layouts, and routing, ensuring efficient performance. SvelteKit offers a comprehensive set of development tools, including server-side rendering, file-based routing, and API endpoints, all seamlessly integrated. This allows us developers to focus on building the application rather than managing complex configurations. SvelteKit is to Svelte what Next.js is to React (for those who are familiar with React).&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;p&gt;Setting up a SvelteKit app is straightforward, and you can get started with just a few commands. Here’s a simple guide to help you set up a new SvelteKit project and an overview of what the repository will contain (note: I highly recommend you check SvelteKit documentation for the latest setup instructions).&lt;/p&gt;

&lt;h3&gt;
  
  
  Setup Instructions
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;First, make sure you have Node.js installed.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Open your terminal or command prompt and run the following command to create a new SvelteKit app:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm init svelte@next my-sveltekit-app
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Replace &lt;code&gt;my-sveltekit-app&lt;/code&gt; with whatever you want to name your project.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Change to your project directory:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;my-sveltekit-app

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

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Install the necessary dependencies using npm:&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;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Run the following command to start the development server:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;This will run your app locally on a server, typically accessible at &lt;code&gt;http://localhost:3000&lt;/code&gt; in your web browser.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  What's Inside the App Repository
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;src&lt;/code&gt; contains all the source files essential for your project. This includes the &lt;code&gt;routes&lt;/code&gt; folder, which contains the pages and endpoints of your application. The structure of files and folders within this folder directly maps to the application's routing; for example, a file named &lt;code&gt;about.svelte&lt;/code&gt; maps to the &lt;code&gt;/about&lt;/code&gt; route. Additionally, there is a &lt;code&gt;lib&lt;/code&gt; folder, intended for reusable libraries and utility functions that support the broader application. The directory also contains &lt;code&gt;app.html&lt;/code&gt;, the main template file where Svelte components are dynamically injected.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;static&lt;/code&gt; directory is for static assets like images, fonts, or plain JavaScript files that don’t need processing.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;svelte.config.js&lt;/code&gt; is the configuration file for SvelteKit. This file includes settings for how your app is built and run.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;package.json&lt;/code&gt; and &lt;code&gt;package-lock.json&lt;/code&gt; handle project metadata and the list of dependencies, respectively.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;node_modules&lt;/code&gt; is a directory that contains all of your project’s npm packages.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.gitignore&lt;/code&gt; specifies intentionally untracked files to ignore (like node_modules).&lt;/li&gt;
&lt;li&gt;Finally, depending on your setup, you might have other config files for tools like ESLint, TypeScript, Tailwind etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This structure provides a solid base for developing complex applications with clear routing and organisation, making it easy to scale up and manage as your project grows.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the &lt;code&gt;.svelte&lt;/code&gt; file
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;&lt;code&gt;.svelte&lt;/code&gt;&lt;/strong&gt; file is a component file used in Svelte applications, and it's where much of the "magic" of Svelte takes place. These files are the building blocks of a Svelte app, allowing you to define structure, style, and behaviour in a single cohesive place. Here’s a breakdown of what goes into a &lt;strong&gt;&lt;code&gt;.svelte&lt;/code&gt;&lt;/strong&gt; file:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;JavaScript&lt;/strong&gt;: The script tag within a &lt;strong&gt;&lt;code&gt;.svelte&lt;/code&gt;&lt;/strong&gt; file contains the component's logic. This can include data properties, computed properties, and functions. The JavaScript in a &lt;strong&gt;&lt;code&gt;.svelte&lt;/code&gt;&lt;/strong&gt; file directly manipulates the component's state and handles its reactivity. Svelte compiles this script into highly efficient imperative code that updates the DOM when the state changes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;HTML&lt;/strong&gt;: The template section of the component, written in regular HTML. This is where you define the structure of your component, like any other HTML file.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CSS&lt;/strong&gt;: Styles specific to this component. Any CSS styles written here are scoped to the component, meaning they won't affect other elements outside this &lt;strong&gt;&lt;code&gt;.svelte&lt;/code&gt;&lt;/strong&gt; file unless explicitly intended. This helps in managing styles without worrying about conflicts across the application.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reactivity&lt;/strong&gt;: Svelte simplifies reactivity, primarily through the use of the '=' operator to automatically update the DOM when a variable changes. This basic method is part of a straightforward syntax. I will explore more of Svelte's reactivity approaches in the next post.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Exports&lt;/strong&gt;: Components can export variables and functions, making them available for use by other components. This is how you can pass props (properties) into components and interact with them.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here’s a simple example of what a &lt;strong&gt;&lt;code&gt;.svelte&lt;/code&gt;&lt;/strong&gt; file might look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script&amp;gt;
  let count = 0;

  function increment() {
    count += 1;  // Automatically updates the DOM wherever `count` is used
  }
&amp;lt;/script&amp;gt;

&amp;lt;h1&amp;gt;Count: {count}&amp;lt;/h1&amp;gt;
&amp;lt;button on:click={increment}&amp;gt;Increment&amp;lt;/button&amp;gt;

&amp;lt;style&amp;gt;
  h1 {
    color: purple;
  }
&amp;lt;/style&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;&lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt;&lt;/strong&gt; block defines a count variable and a function to increment it.&lt;/li&gt;
&lt;li&gt;The HTML structure displays the count and a button that, when clicked, calls the increment function.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;&lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt;&lt;/strong&gt; block scopes its CSS to just this component, ensuring the &lt;strong&gt;&lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt;&lt;/strong&gt; tag is styled as defined only within this component.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Closing Remarks
&lt;/h2&gt;

&lt;p&gt;Svelte opens up a world of possibilities for “easily” creating interactive and efficient web applications. With its intuitive syntax and component-based structure, Svelte, and by extension SvelteKit, offer a streamlined approach to web development that both beginners and seasoned developers come to appreciate.&lt;/p&gt;

&lt;p&gt;As I continue to delve into the capabilities and features of Svelte in future posts, I encourage you to experiment with the concepts and examples shared today. Dive into the documentation, tinker with the code, and see firsthand how enjoyable Svelte is to work with. Whether you're building a small personal project or a large-scale application, the simplicity and power of Svelte are sure to make the development process a rewarding experience.&lt;/p&gt;

&lt;p&gt;Happy coding, and see you in the next post!&lt;/p&gt;

</description>
      <category>svelte</category>
      <category>sveltekit</category>
      <category>webdev</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Learning Svelte &amp; SvelteKit</title>
      <dc:creator>Musab</dc:creator>
      <pubDate>Sun, 31 Mar 2024 16:43:01 +0000</pubDate>
      <link>https://dev.to/moshkh/learning-svelte-sveltekit-7j6</link>
      <guid>https://dev.to/moshkh/learning-svelte-sveltekit-7j6</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsdg3bg3paax4ppuy61d7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsdg3bg3paax4ppuy61d7.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;During my &lt;a href="https://www.linkedin.com/company/northcoders/" rel="noopener noreferrer"&gt;Northcoders&lt;/a&gt; software bootcamp, a mentor introduced us to the State of JS survey, an annual survey that measures the preferences of JavaScript developers, exploring widely used frameworks, favoured frameworks, and those gaining popularity. At the time, we were learning React.js, which I found somewhat challenging. Despite React’s popularity and widespread usage, the survey revealed that another framework, &lt;a href="https://svelte.dev/" rel="noopener noreferrer"&gt;Svelte.js&lt;/a&gt;, scored higher in terms of developer preference and popularity.&lt;/p&gt;

&lt;p&gt;Intrigued by this finding, I dedicated some time after completing the bootcamp to learning basic Svelte and used it to build my first portfolio site. I found it much easier to pick up compared to React, and it was a joy to work with. However, my foray into working with Svelte was short-lived as I landed a job and became busy with the responsibilities that came with it.&lt;/p&gt;

&lt;p&gt;Now, with the goal of building a few Micro-SaaS projects, I recognise the need to refresh my front-end knowledge. I have decided to dive deeper into Svelte.js to further my understanding. To start, &lt;a href="https://vercel.com/docs/beginner-sveltekit" rel="noopener noreferrer"&gt;I’m following a tutorial by Vercel&lt;/a&gt; that covers all the fundamental concepts of SvelteKit which is the equivalent of Next.js for Svelte — once I have a solid foundation I’ll begin building.&lt;/p&gt;

&lt;p&gt;Throughout my learning journey, I’ll write posts / articles on the key concepts of Svelte / SvelteKit as a means of consolidating my knowledge. If you’ve never used Svelte before, I highly recommend exploring it. It’s very easy to set up and most importantly you’ll be pleasantly surprised by its unique (and straightforward) approach to reactivity.&lt;/p&gt;

&lt;p&gt;In my next post I’ll cover more about how Svelte handles reactivity. If you have used Svelte, let me know your thoughts in the comments!&lt;/p&gt;

</description>
      <category>svelte</category>
      <category>sveltekit</category>
      <category>webdev</category>
      <category>vercel</category>
    </item>
    <item>
      <title>TypeScript and the NOT (!) operator in the context of an if statement</title>
      <dc:creator>Musab</dc:creator>
      <pubDate>Thu, 14 Sep 2023 21:42:05 +0000</pubDate>
      <link>https://dev.to/moshkh/typescript-and-the-not-operator-in-the-context-of-an-if-statement-4lgi</link>
      <guid>https://dev.to/moshkh/typescript-and-the-not-operator-in-the-context-of-an-if-statement-4lgi</guid>
      <description>&lt;p&gt;A quick write up on better understanding of the &lt;code&gt;!&lt;/code&gt; (NOT) operator in JavaScript / TypeScript. &lt;/p&gt;

&lt;p&gt;I had to find a way to stop a &lt;code&gt;null&lt;/code&gt; value from progressing to the next statement in a TypeScript file. &lt;/p&gt;

&lt;p&gt;In order to do this I used the &lt;code&gt;!&lt;/code&gt; operator as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;name&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;doingsomethingasync&lt;/span&gt;

&lt;span class="err"&gt;\\&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;can&lt;/span&gt; &lt;span class="nx"&gt;be&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="nx"&gt;or&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;
&lt;span class="err"&gt;\\&lt;/span&gt;&lt;span class="nx"&gt;The&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nx"&gt;statement&lt;/span&gt; &lt;span class="nx"&gt;below&lt;/span&gt; &lt;span class="nx"&gt;catches&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="nx"&gt;keeping&lt;/span&gt; &lt;span class="nx"&gt;TypeScript&lt;/span&gt; &lt;span class="nx"&gt;happy&lt;/span&gt;&lt;span class="o"&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;name&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name is null&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So what's happening here exactly?&lt;/p&gt;

&lt;p&gt;Placing a &lt;code&gt;!&lt;/code&gt; infront of a value does two things&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The value gets coerced to a boolean&lt;/li&gt;
&lt;li&gt;It then gets inverted&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So, if &lt;code&gt;name&lt;/code&gt; is a string, as a coerced boolean it evaluates to &lt;code&gt;true&lt;/code&gt; (remember JavaScript &lt;code&gt;truthy&lt;/code&gt; and &lt;code&gt;falsy&lt;/code&gt;), inverting it means the statement &lt;code&gt;!name&lt;/code&gt; will evaluate to &lt;code&gt;false&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Likewise, if &lt;code&gt;name&lt;/code&gt; is a number, it's coerced to a boolean which evaluates to &lt;code&gt;true&lt;/code&gt;, then inverts to &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;However, if &lt;code&gt;name&lt;/code&gt; is &lt;code&gt;null&lt;/code&gt;, it's coerced to a boolean evaluation of &lt;code&gt;false&lt;/code&gt; (remember &lt;code&gt;null&lt;/code&gt; is &lt;code&gt;falsy&lt;/code&gt; value), when inverted it will evaluate to true.&lt;/p&gt;

&lt;p&gt;This approach ensures the &lt;code&gt;if&lt;/code&gt; statement targeting the &lt;code&gt;null&lt;/code&gt; condition will only execute when &lt;code&gt;name&lt;/code&gt; is &lt;code&gt;null&lt;/code&gt;, permitting a continuation of the program otherwise. &lt;/p&gt;

&lt;p&gt;All in all, &lt;code&gt;!&lt;/code&gt; is thoroughly useful tool to have in the toolbox.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fic1wsf5ytvxb4ipf8xkk.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fic1wsf5ytvxb4ipf8xkk.jpg" alt="Musab Hussain Banner | Musab Hussain, a software developer, writer, lifelong learner and solopreneur" width="800" height="200"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Solving File Path Errors in Node.js: Lessons Learned</title>
      <dc:creator>Musab</dc:creator>
      <pubDate>Tue, 28 Feb 2023 12:23:42 +0000</pubDate>
      <link>https://dev.to/moshkh/solving-file-path-errors-in-nodejs-lessons-learned-1ppn</link>
      <guid>https://dev.to/moshkh/solving-file-path-errors-in-nodejs-lessons-learned-1ppn</guid>
      <description>&lt;p&gt;Working with file paths in Node.js can be tricky and can cause errors if not handled correctly. In this article, I'll discuss the issues I faced while comparing CSV files and how I resolved it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Background
&lt;/h2&gt;

&lt;p&gt;I was comparing two CSV files using a JavaScript Node.js tool I created, where I used the built-in fs module and a well-known CSV parser library called csv-parser. The plan was to parse the files and compare them programmatically.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fs&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;fs&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;csv&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;csv-parser&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;currentProducts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;

&lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createReadStream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../../../../Downloads/current_products.csv&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="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;csv&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;data&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;data&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;currentProducts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Product ID&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="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;end&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="o"&gt;=&amp;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;currentProducts&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The Issue
&lt;/h2&gt;

&lt;p&gt;While executing the above code, I encountered the following error:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Error: ENOENT: no such file or directory, open '../../../../Downloads/current_products.csv&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbp35q4pyw4lsrifsxdxp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbp35q4pyw4lsrifsxdxp.png" alt="File path error message" width="800" height="248"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Troubleshooting and Simple Fix
&lt;/h2&gt;

&lt;p&gt;After some debugging, I realised that Node.js uses the current working directory for resolving file paths rather than the location of the actual script file. In my case, the script file was located in a different directory than the one I was executing the code from.&lt;/p&gt;

&lt;p&gt;To fix this issue, I had two options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ensure that the current working directory (&lt;code&gt;cwd&lt;/code&gt;) is the same as where the script is located, and then run the file.&lt;/li&gt;
&lt;li&gt;OR Use absolute paths / environment variables for the file paths.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I chose the second option by using the &lt;code&gt;path&lt;/code&gt; module to create an absolute path for me.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fs&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;fs&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;csv&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;csv-parser&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;path&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;path&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;currentProductsFile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&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="nx"&gt;__dirname&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../../../../Downloads/current_products.csv&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;currentProducts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;

&lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createReadStream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;currentProductsFile&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;csv&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;data&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;data&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;currentProducts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Product ID&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="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;end&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="o"&gt;=&amp;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;currentProducts&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;path.resolve()&lt;/code&gt; resolves a sequence of paths or path segments into an absolute path. It's useful when working with file paths, providing a reliable way to get the absolute path of a file or directory regardless of the script's location. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;__dirname&lt;/code&gt; in Node.js is a global variable that represents the directory name of the current module.&lt;/p&gt;

&lt;h3&gt;
  
  
  Best Practice
&lt;/h3&gt;

&lt;p&gt;It's always a good practice to know the current working directory of the script, which can be checked by logging &lt;code&gt;process.cwd()&lt;/code&gt;. It's also recommended to use absolute paths or environment variables to ensure that the code works reliably across different directories and machines.&lt;/p&gt;

&lt;p&gt;The Node.js &lt;code&gt;path&lt;/code&gt; module is a great tool to help with building paths, so it's worth checking out.&lt;/p&gt;

&lt;p&gt;In summary, when working with file paths in Node.js:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Remember that Node.js executes from the current working directory.&lt;/li&gt;
&lt;li&gt;Relative paths will resolve based on the current working directory.&lt;/li&gt;
&lt;li&gt;A way to check the current working directory is to log &lt;code&gt;process.cwd()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Try to use absolute paths or environment variables to avoid issues like this.&lt;/li&gt;
&lt;li&gt;The Node.js &lt;code&gt;path&lt;/code&gt; module can help with building absolute paths.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By following these best practices, you can avoid errors and ensure that your code works reliably across different directories and machines.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl6ag39chkysjtye6qo7r.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl6ag39chkysjtye6qo7r.jpg" alt="Musab Hussain Banner | Musab Hussain, a software developer, writer, lifelong learner and solopreneur" width="800" height="200"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>devjournal</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Why am I pursuing a career in software development?</title>
      <dc:creator>Musab</dc:creator>
      <pubDate>Sun, 01 Jan 2023 01:42:05 +0000</pubDate>
      <link>https://dev.to/moshkh/why-am-i-pursuing-a-career-in-software-development-1f5k</link>
      <guid>https://dev.to/moshkh/why-am-i-pursuing-a-career-in-software-development-1f5k</guid>
      <description>&lt;p&gt;In October 2022 I started on a software development bootcamp with Northcoders. My final week of this incredible journey falls on the first week of Jan 2023, a perfect way to welcome in the New Year. I start 2023 on the lookout for a junior developer role equipped with a host of practise based software development skills thanks to &lt;br&gt;
Northcoders.&lt;/p&gt;

&lt;h3&gt;
  
  
  So why did I choose software development?
&lt;/h3&gt;

&lt;p&gt;1) &lt;strong&gt;I love using technology&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Mine isn’t a story of falling in love with programming at 7 years old.. rather it’s been a gradual process that has brought me here. I never delved into “coding” or “programming” per-se up until recently but I have always taken a liking to technology, I’d go as far as saying I am a self-confessed &lt;strong&gt;technophile&lt;/strong&gt; when it comes to technology as an end-user. Off the shelf ready to use software has always been a large part of my life, I have always enjoyed learning, adopting and finding new ways to utilise it in a personal or work capacity.&lt;/p&gt;

&lt;p&gt;2) &lt;strong&gt;Circumstances cause a rethink&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What I did not consider or do, is learn how to code my own scripts / programs / software even with my continual interest in technology. Regularly reading about the shortage of software developers in the public domain eventually led me to explore this field in more depth. I dabbled a little here and there with some very basic scripting, HTML and JavaScript but never really considered changing career paths up until I came across... software development bootcamps.&lt;/p&gt;

&lt;p&gt;The timing of this discovery was perfect if anything as I was at the point in my career where the trajectory did not look appealing and I was actively looking into options for a career change alongside all the other things one has to consider with such a move.&lt;/p&gt;

&lt;p&gt;Keeping my options open I decided to investigate a few different IT roles which had a low enough barrier to entry and had viable re-skill options for me to complete. I considered the following paths:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;IT Administration&lt;/li&gt;
&lt;li&gt;QA Testing&lt;/li&gt;
&lt;li&gt;Software Development&lt;/li&gt;
&lt;li&gt;Data Analysis / Engineering&lt;/li&gt;
&lt;li&gt;Digital Marketing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;3) &lt;strong&gt;The working environment&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;But I kept coming back to software development - Why? The day to day work of designing, building, fixing and maintaining software was the most appealing out of all the above roles. The working conditions, especially the flexibility was also appealing. Additionally, once I had developed strong foundational knowledge I could start working on areas of personal interest / build useful personal projects of which I have a few ideas for.&lt;/p&gt;

&lt;p&gt;4) &lt;strong&gt;Future proofing my career&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Lastly, there is constant evolution in the technology sector - the software development field itself is so vast and perpetually growing that one can spend a joyful lifetime working, learning, creating, exploring and sharing. Not to mention all the important off-shoots such as dev-ops, cloud-engineering, cyber-security etc that one can pursue after some well-grounded experience.  &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;A note:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;“*Give a person a fish, and they will be hungry again tomorrow; teach a person how to fish, they will never be hungry again”&lt;/strong&gt;*&lt;/p&gt;

&lt;p&gt;Why I chose to study with Northcoders:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It is a well established and respected boot-camp, the testimonials speak for themselves both from past students and employers who hire Northcoders graduates.&lt;/li&gt;
&lt;li&gt;The curriculum is designed around employer needs, more importantly they work on building strong foundational knowledge thereby equipping us graduates with the ability to adopt different technology stacks.&lt;/li&gt;
&lt;li&gt;It is local to me, which allowed me to attend in-person at their Leeds office every so often.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I’m thoroughly grateful to the teaching team at Northcoders. it has by no means been an easy journey starting with little to no knowledge to equipping me with the necessary skills for building these two projects on my own - a &lt;a href="https://github.com/moshkh/BE-Project-NC-News" rel="noopener noreferrer"&gt;back-end project&lt;/a&gt; and a &lt;a href="https://github.com/moshkh/fe-project-nc-news" rel="noopener noreferrer"&gt;front-end project&lt;/a&gt;. I'll be finishing Northcoders by working on a full-stack final small-team based project due to be showcased on the 06/01/2023. It has been a truly rewarding experience and I will be leaving knowing &lt;strong&gt;“how to fish”&lt;/strong&gt;, how superb is that!&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;And finally,&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Thank you for taking the time to read about my journey to becoming software developer :)&lt;/p&gt;

&lt;p&gt;If your reading this and are on the lookout for a junior developer, please do get in touch with me! I’d love to explore and consider any relevant opportunities!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8gxtw4ag0fyn0o8zqapp.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8gxtw4ag0fyn0o8zqapp.jpg" alt="Musab Hussain Banner | Musab Hussain, a software developer, writer, lifelong learner and solopreneur" width="800" height="200"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>github</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
