How to Exit from a Node.js Program: A Guide to Gracefully Terminate Your Application

In this technical blog post, we will explore different ways to terminate a Node.js application. While pressing ctrl-C in the console can close a program, we are more interested in discussing programmatically exiting. Let’s start with the most drastic method, which should be avoided. The process core module provides a method called process.exit() that allows you to programmatically exit from a Node.js program. When this line is executed, the process is immediately forced to terminate....

How to Exit Vim: A Quick Guide

Are you struggling to exit Vim? Don’t worry, you’re not alone. Even experienced developers sometimes find themselves stuck in Vim’s command line editor. In this article, we’ll walk you through the steps to escape Vim, whether you want to save your changes or exit without saving. To save your changes and exit Vim, follow these steps: Press the esc key to switch to normal mode. Type :wq to write the changes and quit Vim....

How to Expand Your Blog's Reach with an Email List

In today’s digital age, where social media platforms dominate, you might think that email is an outdated form of communication. However, when it comes to reaching your blog audience, email lists are still one of the most effective tools available. In this article, we will discuss the importance of building an email list and how it can help you expand your reach. What is an Email List? An email list is a collection of email addresses that you have gathered from your blog visitors or customers who are interested in your content or products....

How to Export Functions and Variables from a Svelte Component

In this tutorial, you’ll learn how to export functions and variables from a Svelte component. By exporting additional elements from a component, you can provide other components the ability to access and use them. Let’s dive in! To begin, you may already be familiar with importing a Svelte component into another component using the following syntax: <script> import Button from './Button.svelte'; </script> But what if you want to export something more than just the default export?...

How to Extend a Class in JavaScript: A Guide to JavaScript Inheritance

JavaScript inheritance allows you to extend the functionality of a class by creating subclasses. In this guide, we’ll explore how to extend a class in JavaScript and provide specific methods and properties. Let’s start with the base class, “Animal”: class Animal { breathe() { //... } } In this case, all animals breathe. However, not all animals can walk or fly. To handle this, we can create subclasses that extend the base class and inherit the “breathe()” method....

How to extract the last segment from a path or URL using JavaScript

When working on a project, you may come across the need to extract the last segment from a path or URL. Whether it’s a filesystem path or a website URL, the following JavaScript code can help you achieve that: const lastItem = thePath.substring(thePath.lastIndexOf('/') + 1); To understand how this code works, let’s break it down: We define a thePath string that represents the path or URL, such as /Users/Flavio/Desktop. By calling lastIndexOf('/') on thePath, we find the index of the last occurrence of the forward slash (/) character....

How to feed data to a Next.js component using getInitialProps

When adding dynamic content to Next.js, there may be instances where you need to dynamically generate a page that requires data upfront. One way to achieve this is by utilizing the getInitialProps function. In this blog post, we will explore how to feed data to a Next.js component using getInitialProps. First, let’s take a look at an example where we encountered an issue while trying to get data from a JSON file for a dynamically generated post page....

How to Fill and Empty the Developer Bucket: Finding Fulfillment in the Tech Community

As developers, we all have what I like to call a “developer bucket” - a metaphorical reservoir of fulfillment and motivation that can either be filled or emptied by our actions and interactions within the tech community. Every time we post a negative comment, criticize someone’s work, or spread hostility, a little bit of our developer bucket leaks. On the other hand, every time we show kindness, appreciation, and support, we can fill not only our own bucket, but also the buckets of other developers....

How to Filter an Array in JavaScript

In JavaScript, filtering an array to get a new array with specific values is a common task. Thankfully, JavaScript arrays provide a built-in method called filter() that makes this process easy and efficient. Let’s say we have an array called dogs with four objects, each representing a different dog: const dogs = [ { name: 'Roger', gender: 'male' }, { name: 'Syd', gender: 'male' }, { name: 'Vanille', gender: 'female' }, { name: 'Luna', gender: 'female' } ]; If we want to filter this array to get only the male dogs, we can use the filter() method....

How to Find Duplicates in an Array using JavaScript

Finding and removing duplicates in a JavaScript array can be achieved using various methods. In this blog post, we will explore two common approaches: using the Set data structure and sorting the array. Using the Set Data Structure To remove duplicates from an array, you can utilize the Set data structure offered by JavaScript. This can be done in just one line of code: const yourArrayWithoutDuplicates = [...new Set(yourArray)]; By spreading the Set object into an array, you can obtain a new array without any duplicate elements....