Cannot connect to Neon database

hi, i am trying to connect my application using nestjs with neon db, but i am getting error message “connection is insecure (try using sslmode=require)” , how can i fix it ? Thanks

Can you try adding ?sslmode=require at the end of the connection string?

Hi Stas, where can i add ? thank you

As per TypeORM / postgres.js documentation you most likely can add ssl: 'require' key to the settings

I am getting this same error using NestJS and Neon, do you have any updates, or did you get this to work @Stas_Kelvich & @phuonghust2110 ?

I just got it to work here’s my code:

@Module({
    imports: [
        ConfigModule.forRoot({ isGlobal: true }),
        TypeOrmModule.forRoot({
            type: 'postgres',
            host: process.env.POSTGRES_HOST,
            port: parseInt(<string>process.env.POSTGRES_PORT),
            username: process.env.POSTGRES_USER,
            password: process.env.POSTGRES_PASSWORD,
            database: process.env.POSTGRES_DATABASE,
            autoLoadEntities: true,
            options: { encrypt: false },
            logging: true,
            synchronize: true, // shouldn't really be used in production - may lose data

            ssl: true,
            extra: {
                ssl: {
                    rejectUnauthorized: false,
                },
            },
        }),
        SummaryModule,
        AuthModule,
    ],
    controllers: [AppController],
    providers: [
        AppService,
        {
            provide: APP_FILTER,
            useClass: AllExceptionsFilter,
        },
    ],
})
4 Likes

Hi, please am also experiencing this on my project and have added sslmode=require but it still throwing the error please how can I go about this issue? thank you.

I see that you are connecting from Sequelize. Please see this post: