Node

Cascade Delete in TypeORM

Updated: September 27, 2022 By: Snowball

When working with a database, the cascade delete feature ensures that deleting a parent record will also remove the child records. For instance, we have a table that stores information about users and another table that…

Node.js + Express + TypeScript: req.query type

Updated: September 14, 2022 By: Snowball

When working with Node and Express.js, there might be cases where you need to access req.query, an object that contains the property for each query string parameter in the route. For example, given a route like…

Node.js Error: listen EADDRINUSE: Address already in use

Updated: September 14, 2022 By: A Goodman

This quick article shows you how to solve a common error you might confront when working with Node.js. The Problem When developing a Node.js application (with Express.js), I sometimes fall into the following problem: Full error…

Nodemon: Automatically Restart a Node.js App on Crash

Updated: September 13, 2022 By: Guest Contributor

A large number of developers use Nodemon during the development and testing of Node.js apps. When your code file changes, Nodemon will automatically restart the program. However, when the app crashes, it will stop: This is…

How to Use Subqueries in TypeORM

Updated: January 30, 2024 By: Snowball

This article is about using subqueries with query builders in TypeORM. Let’s say we have an entity named Product: The code snippet below finds products with a higher than average price by using a subquery (that…

TypeORM: Sort Results by a Relation Column

Updated: January 30, 2024 By: Pennywise

When using TypeORM to interact with databases, there might be occasions when you want to take records and sort them based on a relational field. There are 2 solutions for this: using find options and using…

Node.js: Turn a Relative Path into an Absolute Path

Updated: September 1, 2022 By: Snowball

In Node.js, you can convert a relative path to an absolute path simply by using the path module, like this: This is my output on macOS (if you’re using Windows, your result will be more or…

TypeORM: Find Rows Where Column Value is IN an Array

Updated: August 31, 2022 By: A Goodman

This short and straight-to-the-point article shows you 2 different ways to use the WHERE IN query in TypeORM (in case you want to search for rows whose column values are an element of a given array)….

How to Store JSON Object with TypeORM

Updated: August 31, 2022 By: A Goodman

If you want to store some kind of flexible data with TypeORM, you can save them as JSON. You can specify the column type as simple-json. This helps you store and load Javascript objects with ease….

TypeORM: Add Columns with Array Data Type

Updated: August 31, 2022 By: A Goodman

When using TypeORM, it’s possible to define columns with the array data type. If you want to add a column that stores arrays of numbers, you can define it like so: In case you need a…

Pagination in TypeORM (Find Options & QueryBuilder)

Updated: May 20, 2022 By: Pennywise

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 from…

TypeORM: Entity with Decimal Data Type

Updated: May 20, 2022 By: Pennywise

In TypeORM, you can add a column with decimal data type like this: Where: precision: The number of digits in the decimal scale: The number of digits to the right of the decimal point Full example:…

1 2 3 5