Cascade Delete in TypeORM
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
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
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
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
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
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
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
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
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
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)
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
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:…