Node.js: Get domain, hostname, and protocol from a URL

January 19, 2021 Guest Contributor

By using the URL class, a built-in module of Node.js, we can easily extract domain/hostname and protocol from a given url without using any third-party package. Domain, hostname, and protocol A domain name is the address…

NPM: How To Show All Globally Installed Packages

September 21, 2020 Saul Goodman

To show all globally installed npm packages on your computer, just run the following command: Here is my output: If you want to see all global packages and their dependencies, use this:

How to generate slugs from titles in Node.js

June 19, 2020 Linda Walker

A slug is the part of a URL that describes something about a webpage’s content. For example, we have a URL like this: Then the slug is: A slug often contains only some “friendly” characters in…

How to easily generate a random string in Node.js

June 18, 2020 Ken Fisher

This article introduces to you an easy way to generate random strings in Node.js using the randomBytes API provided by the crypto module (a built-in module and no installation required). The code: The output will look…

Node.js: Reading content from PDF and CSV files

January 19, 2021 Saul Goodman

Introduction Node.js is non-blocking I/O so it is efficient when working with files even super large files. PDF, which stands for Portable Document Format, is used to display text and images independently with software and hardware….

How to resize images using Node.js

June 10, 2020 Saul Goodman

Resizing images in Node.js is super easy with a library named gm. To use this one, you need to install ImageMagick first. Here is the download page for Windows, Linux, and macOS. After installing ImageMagick, open…

Using Axios to download images and videos in Node.js

January 22, 2021 Saul Goodman

Node.js is an asynchronous event-driven Javascript runtime that is designed to build scalable network applications. When handling files (from small images to large videos) with Node.js, you are free from the worries of dead-lock the process…

Crawling Facebook with Node.js and Puppeteer

June 9, 2020 Saul Goodman

Puppeteer is a great library for Node.js which can help you crawl data from modern websites that using Javascript (React, Angular, Vue, jQuery Ajax…) to load and render content. In this tutorial, we’ll build a simple…

Check computer RAM size with Node.js

May 28, 2020 Saul Goodman

The built-in os module in Node provides methods that help you check your memory size. Note that 1 MB = 1024 KBs and 1KB = 1024 byte.

Get the number of CPU cores in Node.js

May 28, 2020 Saul Goodman

Node has a built-in module called os that can help you find out how many cores your CPU has. Example:

Excluding node_modules when using tree command on Mac

May 28, 2020 Saul Goodman

The node_modules folder is often super big and contains countless files and subdirectories. Therefore, when using the tree command to display your project structure, you should ignore node_modules. To do so, try this: The result: If…

Express: Automatically download an image when clicking a link

April 30, 2020 Saul Goodman

The simple project below will show you how to automatically download an image served from Express server when clicking a link. Our project structure: The code in app.js (don’t forget to install express before running your…

1 2