Node.js: How to Compress a File using Gzip format
In Node.js, you can compress a file using the Gzip format by using streams. We can get the job done with just a few lines of code and there is no need to install any third-party…
Node.js: The Maximum Size Allowed for Strings/Buffers
Buffers and strings in Node.js are limited in size. The actual maximum size of a buffer or a string changes across platforms and versions of Node.js. You can check yours as follows: Here’s my output: Further…
5 Ways to Read JSON Files in Node.js
This article walks you through a bunch of different ways to read JSON files in Node.js. Without any further ado, let’s get our hands dirty by writing some code. Getting Started This is the sample JSON…
Node.js: Using __dirname and __filename with ES Modules
If you’re building a Node.js application with ES modules instead of CommonJS modules (“import” instead of “require”, in simpler terms), you have to do something before writing __filename and __direname in your code. The Problem In…
Tweaking a Node.js Core Module
The example below shows you how to change the behavior of a Node.js core module by modifying or extending it. What we are going to do should not appear in serious products but might be somehow…
Node.js: Getting User Input from Console (2 approaches)
This article walks you through a couple of different ways to get user input from the console in a Node.js program. The first approach is to do things from scratch with only built-in features of Node.js….
Node.js: Use Async Imports (Dynamic Imports) with ES Modules
Overview Nowadays, many modern Node.js applications use ES modules (that go with the import keyword) instead of CommonJS modules (that go with the require keyword). When working with ES modules, there might be scenarios where you…
How to Install Node.js on Ubuntu 20.x/21.x/22.x
This article shows you how to install Node.js and NPM on Ubuntu 20.04 (Focal Fossa), Ubuntu 20.10 (Groovy Gorilla), Ubuntu 21.04 (Hirsute Hippo), Ubuntu 21.10 (Impish Indri), Ubuntu 22.04 (Jammy Jellyfish), and Ubuntu 22.10 (Kinetic Kudu)….
Node.js: Generate Images from Text Using Canvas
The example below shows you how to programmatically generate images from text in Node.js by using the canvas library. Example Here’s the image we are going to “draw” with code: The code 1. Install the library:…
Node.js: Reading and Parsing Excel (XLSX) Files
This article shows you how to read and extract content from an Excel (.xlsx) file by using Node.js. Without any further ado, let’s get our hands dirty and start coding. Getting Things Ready We are going…
Node.js: How to Ping a Remote Server/ Website
This article shows you a couple of different ways to programmatically ping a remote server or a website from within your Node.js application (to get some network information like latency, IP address, …). In the first…
Express + TypeScript: Extending Request and Response objects
This article shows you how to add new properties to an Express request object (we often deal with this task when working with middleware) or an Express response (not too common but may be necessary in…