TypeOrm – Nest.js Failed to connect to XX:1433 – self signed certificate

Solution for TypeOrm – Nest.js Failed to connect to XX:1433 – self signed certificate
is Given Below:

When trying to connect to SQL Server, I get the following error:

[Nest] 96151  - 30/07/2021 18:28:34   ERROR [TypeOrmModule] Unable to connect to the database. Retrying (1)...
ConnectionError: Failed to connect to XXXXXX:1433 - self signed certificate*

My ormconfig.json:

{
    "type": "mssql",
    "host": "localhost",
    "port": 1433,
    "username": "user",
    "password": "pass",
    "database": "BDname",
    "entities": ["dist/**/*.entity{.ts,.js}"],
    "synchronize": true
}

You just need to add in ormconfig.json and works for me

“options”: {“trustServerCertificate”: true}

{
    "type": "mssql",
    "host": "XXXXXX",
    "port": 1433,
    "username": "user",
    "password": "pass",
    "database": "BDName",
    "entities": ["dist/**/*.entity{.ts,.js}"],
    "synchronize": true,
    "options": {"trustServerCertificate": true}   
}