KindaCode

Node

Node.js tutorials, tips & tricks

Excluding node_modules when using tree command on Mac

Updated: Feb 23, 2022

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: tree -I......

A few examples of exports and require in Node.js

Updated: Feb 23, 2022

A few easy-to-understand examples that will help you understand “exports” and “require” in Node.js better. Example 1 Exports: // your-file.js const firstMethod = () => { // do something } const......

Using ENUM Type in TypeORM

Updated: Feb 08, 2022

If you’re working with PostgreSQL or MySQL and making use of TypeORM in your code then you can add a column with the ENUM (enumerated) data type like so: // book.entity.ts import { Entity, PrimaryGeneratedColumn, ......

TypeORM: Adding created_at and updated_at columns

Updated: Feb 06, 2022

In TypeORM, you can add a created_at column and a updated_at column by making use of the CreateDateColumn and UpdateDateColumn decorators, respectively. These columns will be automatically initialized and updated to the current date......

Node + TypeScript: Export Default Something based on Conditions

Updated: Feb 04, 2022

There might be times when you might want to export something based on one or multiple conditions (for example, you want to export configuration information like database, API keys, etc for development environment and production......

Node.js: How to Compress a File using Gzip format

Updated: Nov 29, 2021

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 packages. Example: // Kindacode.com Example const......

Node.js: The Maximum Size Allowed for Strings/Buffers

Updated: Nov 29, 2021

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: const buffer = require('buffer'); // Get the......

Tweaking a Node.js Core Module

Updated: Nov 18, 2021

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 helpful for learning and testing......

Node.js: Generate Images from Text Using Canvas

Updated: Nov 11, 2021

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......

Node.js: Executing a Piece of Code after a Delay

Updated: Aug 26, 2021

In Node.js, we can use the setTimeout function to run a piece of code after a delay. You can call setTimeout directly or use it with async/await. Example 1 – setTimeout This code runs a function named sayHello after 1000......

Page 5 of 5