Kinda Code
Home/Node/Page 4

Node

Node.js tutorials, tips & tricks
Node.js: 2 Ways to Colorize Console Log Output

Node.js: 2 Ways to Colorize Console Log Output

Updated: Jul 10, 2022
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 you print a few short messages......
Pagination in TypeORM (Find Options & QueryBuilder)

Pagination in TypeORM (Find Options & QueryBuilder)

Updated: May 20, 2022
This short and straight-to-the-point article shows you how to paginate data in TypeORM. Using Find(), FindAndCount() methods If you use a find method, you can implement pagination with the skip and take options: skip: offset......
TypeORM: Entity with Decimal Data Type

TypeORM: Entity with Decimal Data Type

Updated: May 20, 2022
In TypeORM, you can add a column with decimal data type like this: @Column({type: "decimal", precision: 10, scale: 2, default: 0}) price: number; Where: precision: The number of digits in the decimalscale: The number of......
Node.js: 2 Ways to Delete All Files in a Folder

Node.js: 2 Ways to Delete All Files in a Folder

Updated: May 11, 2022
There might be cases where you want to empty an entire folder in Node.js. This article shows you a couple of different ways to do so. The first approach uses self-written code while the second one makes use of a third-party package.......
Node.js: Listing Files in a Folder

Node.js: Listing Files in a Folder

Updated: May 08, 2022
In Node.js, you can asynchronously list all files in a certain directory by using fs.promises. Example I have a Node.js project with the file structure as follows: . ├── files │ ├── a.jpg │ ├── b.png │ ├── c.xml │ ......
TypeORM: How to Limit Query Execution Time

TypeORM: How to Limit Query Execution Time

Updated: Apr 23, 2022
When performing CRUD operations with TypeORM, you can set timeout (maximum execution time) for a certain query like so: const productRepository = dataSource.getRepository(Product); const products = await productRepository ......
TypeORM: How to store BIGINT correctly

TypeORM: How to store BIGINT correctly

Updated: Apr 22, 2022
If you’re using TypeORM to work with PostgreSQL or MySQL and want to save BIGINT (from -2^63 (-9,223,372,036,854,775,808) to 2^63-1 (9,223,372,036,854,775,807)) to your database, you have to define your column as......
How to change NPM cache location (Windows & Mac)

How to change NPM cache location (Windows & Mac)

Updated: Mar 19, 2022
This concise article shows you how to change the npm cache folder in Windows and macOS. Without any further ado, let’s get started. Windows The default npm cache folder in Windows is: %AppData%/npm-cache You can set......
Node.js: Get File Name and Extension from Path/URL

Node.js: Get File Name and Extension from Path/URL

Updated: Mar 19, 2022
The path module (one of the core modules of Node.js) gives us some methods to simply retrieve the name and extension of a file from a path or web URL: path.basename(path: string, extension?: string): Returns the file name with the......
Node + Express: Download files with res.download()

Node + Express: Download files with res.download()

Updated: Mar 19, 2022
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: npm init 2. Install express: npm i......
How to get all Links from a Webpage using Node.js and Cheerio

How to get all Links from a Webpage using Node.js and Cheerio

Updated: Mar 19, 2022
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......
TypeORM: Adding Fields with Nullable/Default Data

TypeORM: Adding Fields with Nullable/Default Data

Updated: Feb 25, 2022
By default, every field (column) of a TypeORM entity is NOT NULL. You can make a specific field become nullable by setting the nullable option to true, like this: // book.entity.ts import { Entity, PrimaryGeneratedColumn, ......