Implementing a secure password reset in Node.js

Note: This article first appeared on the LogRocket blog Creating a strong password that you can actually remember isn’t easy. Users who use unique passwords for different websites (which is ideal) are more likely to forget their passwords. So, it’s crucial to add a feature that allows users to securely reset their password when they forget it. This article is about building a secure reset password feature with Node.js and Express.js. Now, let’s…

The guide to signal handling in Rust

A signal is a software interrupt sent to a process by the operating system or another process to notify it of an event. For example, when you try pressing Control+C while your program runs on a terminal, it terminates the process, correct? That’s one of the most common signals and signal handling you can see in action. We’ll explore how to handle that signal and others in Rust. A signal can be…

Understanding Closures in Rust

Like several other languages, Rust programming language supports closures also known as anonymous functions or lambda functions which is a powerful feature used for varying reasons depending on who you ask. We’ll break down closures in Rust in this article, so you can start using it in your Rust code immediately and properly. A closure in Rust is a function without a name that can be used as a variable.…

Rust’s Newtype Pattern: Adding Type Safety and Clarity

The newtype pattern is a Rust idiom that can be used to add type safety and clarity to code. At its core, the newtype pattern involves wrapping an existing Rust type (like a number or a string) inside a new struct. This might seem unnecessary at first, but the magic is that this new struct becomes a distinct type and ensures that you are using the correct type where necessary.…

Building a simple Rust webserver

What comes to mind when you think of building a web server with Rust? I bet you think of using Axum, Rocket, Actix, etc., right? These are mature frameworks for building web applications with Rust. By the end of this article, we’ll learn how to build a web server of our own that will receive a get or post request and respond to it without any of those shiny frameworks.…

Mem::replace in Rust

mem::replace is a Rust standard library function that swaps a value in a variable with a new value while returning the original value. In Rust, when you move data out of a container like Vec or Option, the container can no longer be directly used, as its contents have been moved and it is considered empty or invalidated. Imagine a scenario where you want to take the data out of…

Box Smart Pointer in Rust

Box smart pointer is a pointer in Rust that allows you to allocate memory on the heap, even though the Box pointer itself exists in the stack. Key notes: To create a Box, you can use the Box::new() function. This function takes the value that you want to store on the heap and returns a Box that points to the allocated memory. You can access the data stored in the…

Understanding Dereferencing in Rust

Dereferencing is how we access the value that a reference points to. References are like signposts that guide us to the actual data. Imagine them as arrows pointing to a treasure! 💎 Technically, a pointer stores the address of another variable in memory. So, if we do something like the example below: my_ref will hold the address of x in memory. In that case, x is not equal to my_ref, make…

Rust Lifetimes Simplified

This guide is an attempt to simplify Rust Lifetimes, it’s a series and will be divided into several chapters. We’ll start with chapter one today. Chapter 1 Lifetimes and its benefits In Rust programming, lifetimes is a critical yet misunderstood concept. Assuming we are not talking about programming, when we talk about lifetimes what comes to mind? According to Oxford Dictionary, a lifetime is the duration of a person’s life…

Node.js: boost perf with worker threads

Node.js is a powerful and efficient tool. However, because it is single threaded we might have issues when working with CPU-intensive operations. For example, when you try to upload large JSON or media files. This operation will most likely block the main thread and every other operation will have to wait until it’s completed. First off, what is a worker thread in Node.js? A worker thread is a sequence of instructions within…