NPM: How To Show All Globally Installed Packages
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: That’s it. Further reading:…
How to Generate Slugs from Titles in Node.js
This article shows you a few approaches to generating a slug from a title in Node.js. The first one is to use self-written code and the other is to use a third-party package. Introduction A slug…
3 Ways to Generate Random Strings in Node.js
This article walks you through 3 different ways to generate a random string in Node.js. The first two approaches only use self-written code and utilize the built-in functionality of Node.js. The last approach introduces to you…
How to Resize Images using Node.js
This article walks you through a couple of different ways to programmatically resize images in Node.js. Using sharp The sharp package is fast in converting large images to smaller ones. It works well with JPEG, PNG,…
Check computer RAM size with Node.js
The built-in os module in Node provides methods that help you check your machine’s memory size: os.totalmem(): Returns the total amount of system memory in bytes. freemem(): Returns the amount of free system memory in bytes….
Get the Number of CPU Cores in Node.js
The standard module os of Node.js provides a lot of operating system-related utilities. The os.cpus() method returns an array of objects containing information about each logical CPU core. To count the number of CPU cores, we…
Excluding node_modules when using tree command on Mac
The node_modules folder is often super big and contains countless files and subdirectories. Therefore, when using the tree command to display your project file structure, you should ignore node_modules. To do so, try this: The result:…
Node + Express: Download files with res.download()
The example below shows you how to automatically download an image served from Express server when clicking a link. 1. Navigate to the folder you want your project to lie in then run: 2. Install express:…
Node.js: 2 Ways to Colorize Console Log Output
By default, when you print out something by using console.log() in Node.js, the output is usually white if your terminal has a dark background color or black if your terminal has a light background color. If…
A few examples of exports and require in Node.js
A few easy-to-understand examples that will help you understand “exports” and “require” in Node.js better. Example 1 Exports: Require (file index.js) Examples 2 Export (call it your-file.js or whatever you like): Require: Further reading: 2 Ways…
How to get all Links from a Webpage using Node.js and Cheerio
Node.js is a javascript runtime environment that helps you create high-performance apps. Because Node.js functions are non-blocking (commands execute concurrently or even in parallel, it can perform heavy tasks without incurring the cost of thread context…
« Previous 1 … 3 4 5