The database is running in Docker, but I keep getting this error when start the app with the command 'npm run start'
Here is my database configuration :
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigModule, ConfigService } from '@nestjs/config';
@Module({
imports: [
ConfigModule,
TypeOrmModule.forRootAsync({
useFactory: (configService: ConfigService) => ({
type: 'postgres',
host: configService.get<string>('DB_HOST', 'localhost'),
port: configService.get<number>('DB_PORT', 5432),
username: configService.get<string>('DB_USER'),
password: configService.get<string>('DB_PASS'),
database: configService.get<string>('DB_NAME'),
synchronize: configService.get<string>('NODE_ENV') !== 'production',
logging: configService.get<string>('NODE_ENV') === 'development',
autoLoadEntities: true,
}),
inject: [ConfigService],
}),
],
exports: [TypeOrmModule],
})
export class DatabaseModule {}
And my docker-compose file:
services:
postgres:
env_file:
- .env
image: postgres
restart: on-failure
environment:
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASS}
POSTGRES_DB: ${DB_NAME}
ports:
- '5432:5432'
expose:
- 5432
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U ${DB_USER} -d ${DB_NAME}']
interval: 10s
timeout: 5s
retries: 5
volumes:
- db-data:/var/lib/postgresql/data
7am-club:
build:
context: .
command: npm run start:dev
environment:
NODE_ENV: ${NODE_ENV:-development}
ports:
- 3000:3000
depends_on:
postgres:
condition: service_healthy
volumes:
db-data:
And .env example:
DB_HOST=postgres
DB_PORT=5432
DB_USER=test
DB_PASS=test123
DB_NAME=test
Everything is pretty basic as I've been following the Nest documentation, but for some reason it doesn't work and I don't understand why
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744199546a4562814.html
评论列表(0条)