Processing Redirects in Express: A Guide for Server-side Redirection

Redirects play a crucial role in web development by allowing you to efficiently direct users to other pages. In this guide, we will explore how to handle redirects using Express, a popular web application framework for Node.js. To begin with, you can initiate a redirect using the Response.redirect() method. Let’s take a look at a simple example: res.redirect('/go-there'); By using this code snippet, a 302 redirect will be created, indicating a temporary redirect....

Roadmap for Learning the Web Platform: A Comprehensive Guide

The Web Platform is a powerful and diverse ecosystem comprising of APIs, tools, and languages. It offers endless possibilities for developers. If you are looking for a roadmap to learn the Web Platform, you’ve come to the right place. In this blog, I have compiled a collection of tutorials and articles that will help you navigate the Web Platform with ease. Let’s get started! Browser API Guides Begin your journey by diving into the Document Object Model (DOM), which is the fundamental API exposed by browsers....

Running a Web Server from Any Folder

Running a web server from a specific folder on your system can be a common requirement. However, configuring a full-fledged web server like Apache or Nginx might not be practical for quick testing or temporary use. Fortunately, depending on your preferred programming language, you may already have the necessary tools at your disposal. Node.js Approach If you use Node.js and have already installed npm, you can easily accomplish this task. Start by running the following command:...

Setting up an Nginx Reverse Proxy for Serving Multiple Node.js Apps from Subfolders

If you’re running multiple Node.js scripts under the same domain on a VPS like DigitalOcean, you’ll need to use a reverse proxy since two Node.js apps can’t listen on the same port. Nginx is a popular choice for setting up a reverse proxy. To begin, you’ll need to edit the Nginx configuration file: sudo nano /etc/nginx/sites-available/default The default configuration file looks like this: server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; index index....

SQL Injection: Protecting Your Application from Attacks

SQL injection poses a significant threat to database-driven applications that rely on SQL queries. The vulnerability lies in the lack of input sanitization, which allows attackers to manipulate the queries’ behavior. Let’s take a look at a simple Node.js example to understand how SQL injection can occur: const color = // coming from user input const query = `SELECT * FROM cars WHERE color = '${color}'` In this case, if the value of color is a legitimate color like “red” or “blue”, the query works as intended....

The Evolution of JavaScript in the Last Decade

Looking back at the last decade of JavaScript and the evolution of the web, it has been a truly remarkable journey. In 2010, JavaScript wasn’t as widely used as it is today. While I had JavaScript books from as early as 1998 in my library, I mainly used it in the form of Mootools and jQuery plugins. Although I wrote some glue code in JavaScript, it wasn’t anything groundbreaking. Back then, JavaScript was not considered a hot language, except for projects like GMail and Google Maps that required advanced work and large budgets....

The Guide to package.json for SEO-friendly Blogs

The package.json file is an essential component in many Node.js-based app codebases. If you work with JavaScript or have interacted with a JavaScript project, Node.js, or a frontend project, it’s likely that you are familiar with the package.json file. But what exactly is it for? What should you know about it, and what can you do with it? In this guide, we will explore the package.json file, its structure, and its properties....

The Node Core Modules: A Comprehensive Overview

Node.js, a popular runtime environment for executing JavaScript code on the server-side, comes with a rich set of core modules. These modules are included in the Node.js installation and provide essential functionalities for building efficient and scalable applications. In this article, we will explore each of these core modules and their key features. Core Modules Provided by Node.js Node.js provides the following core modules: assert: This module offers a set of assertion functions that are useful for testing and validating code....

The Node path module: Simplify File Path Operations for Easy File System Interaction

The path module in Node.js is a powerful tool that comes pre-installed with Node.js. It offers a wide range of functionality to easily access and interact with file paths in the file system. To begin using the path module, simply require it in your code: const path = require('path'); The path module provides two important properties: path.sep, which represents the path segment separator (\ on Windows and / on Linux/macOS), and path....

The npx Node Package Runner: A Powerful Tool for Running Node Code

npx, a command available in npm since version 5.2, is an incredible tool for running Node code efficiently and comes packed with useful features. In the following post, I will introduce npx and explore its capabilities. Easily Run Local Commands Previously, Node developers used to publish executable commands as global packages to make them readily available in the path. However, this approach had limitations, mainly regarding version control. With npx, you can simply run npx commandname to automatically locate the correct reference of the command within the node_modules folder of your project....