2

When running heroku config I see (with some omissions)

DATABASE_URL: postgres://<xxxx>:<xxxx>@ec2-xx-xx-xxx-xx.compute-1.amazonaws.com:5432/dm74hmu71b97n

which I know is of form postgres://<user>:<password>@<hostname>:<port>/<database>. But right now in my Nest.JS app I connect to postgres like this:

@Module({
    imports: [
        TypeOrmModule.forRootAsync({
            imports: [ConfigModule],
            inject: [ConfigService],
            useFactory: (configService: ConfigService) => ({
                type: 'postgres',
                host: configService.get('POSTGRES_HOST'),
                port: configService.get('POSTGRES_PORT'),
                username: configService.get('POSTGRES_USER'),
                password: configService.get('POSTGRES_PASSWORD'),
                database: configService.get('POSTGRES_DB'),
                entities: [__dirname + '/../**/*.entity{.ts,.js}'],
                synchronize: false,
            }),
        }),
    ],
})
export class DatabaseModule {}

I suppose I could manually parse process.env.DATABASE_URL I figured there must be a better/easier way.

1 Answer 1

4
useFactory: (configService: ConfigService) => ({
    url: configService.get('DATABASE_URL'),
    type: 'postgres',
    entities: [__dirname + '/../**/*.entity{.ts,.js}'],
    synchronize: false,
}),
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.