Database connection
First, we should connect to the database.
Let's create a DatabaseModule to connect to the database.
nest g mo databaseIn its imports array, add the following:
TypeOrmModule.forRoot({
type: 'postgres',
username: 'postgres',
password: 'pass123',
host: 'localhost',
port: 5432,
database: 'postgres',
autoLoadEntities: true,
})Commit - Connecting to database
All right, we established a connection to the database. But this solution is not very interesting, don't you think? We are exposing all our credentials here. The same problem appeared again.
In the Configuration section, we'll learn how to fix this issue through the usage of environment variables and also have validation/typing for them.
Last updated