...

/

Connecting to PostgreSQL using TypeORM

Connecting to PostgreSQL using TypeORM

Learn how to connect to the PostgreSQL database with TypeORM in NestJS application.

In the previous sections, we explored building a virtual library storing books in application memory. While straightforward, this approach has significant drawbacks. It limits scalability and offers no data persistence. For instance, a server restart wipes out all stored books, making the library volatile and unreliable. This section will set up a robust, permanent storage solution using a PostgreSQL database and TypeORM.

Press + to interact
Fetching books data with TypeORM in PostgreSQL database
Fetching books data with TypeORM in PostgreSQL database

Installation

We need to install several essential dependencies to proceed with the setup. These include the database driver for PostgreSQL and the NestJS ORM library, TypeORM.

Note: When following along this course, the packages are preinstalled. You can run the command below if you’re on a local setup.

Run the following command to install the required packages:

 ...