title: How to change the TypeORM config dynamically on a NestJS server?
body: <p>I'm trying to create an endpoint to configure my NestJS server. Basically, the endpoint will create my environment file(.env).</p>
  
  <p>My problem is when I start my NestJS server for the first time I don't have the variables for the TypeORM, so when the TypeORM module is imported the server crash because it can find the configuration.</p>
  
  <p>So I'm trying to find a way to start my NestJS server without importing the TypeORM module or importing the TypeORM without the configuration and add it later when I have the environment variables set.</p>
  
  <p>mysql-database.module.ts</p>
  
  <pre class="lang-js prettyprint-override"><code>...
  @Module({
    imports: [TypeOrmModule.forRoot()],
    providers: [MysqlDatabaseService],
    exports: [MysqlDatabaseService],
  })
  ...
  </code></pre>
  
  <p>.env (That are the variables that are not set when I start the NestJS for the first time)</p>
  
  <pre><code>...
  TYPEORM_CONNECTION = mysql
  TYPEORM_HOST = localhost
  TYPEORM_USERNAME = root
  TYPEORM_PASSWORD = root
  TYPEORM_DATABASE = mydb
  TYPEORM_PORT = 3306
  TYPEORM_SYNCHRONIZE = true
  TYPEORM_LOGGING = true
  TYPEORM_ENTITIES = src/**/*.entity.ts
  
  </code></pre>