I am trying to connect to MySQL. I have defined the db connection vars in a .env file in my root dir, and I am initializing the connection in the app.module.ts file. the only issue I am facing now is when creating or running migrations using the CLI, I followed the typeorm docs here to configure the connection, however when I run typeorm migrate:create -n myNewTable, it should create the migration file in the specified directory, what it does instead is it creates it in the app root directory, similarily, I solved the issue by using the -d flag after the typeorm migrate:create to specify the directory, however when I try running my migration files, I get this
No connection options were found in any of configurations file.
here is my app.module.ts file.
TypeOrmModule.forRoot({
type: 'mysql',
host: process.env.TYPEORM_HOST,
port: parseInt(process.env.TYPEORM_PORT, 10),
username: process.env.TYPEORM_USERNAME,
password: process.env.TYPEORM_PASSWORD,
database: process.env.TYPEORM_DATABASE,
synchronize: false,
migrations: [process.env.TYPEORM_MIGRATIONS],
cli: {
migrationsDir: process.env.TYPEORM_MIGRATIONS_DIR,
},
logging: (process.env.TYPEORM_LOGGING === 'true') ? true : false,
entities: [__dirname + '/../**/*.entity{.ts,.js}'],
}),
Run code snippetExpand snippet
and here is my .env file
# use .ts for development, .js for production
TYPEORM_CONNECTION = mysql
TYPEORM_HOST = 127.0.0.1
TYPEORM_PORT = 3306
TYPEORM_USERNAME =
TYPEORM_PASSWORD =
TYPEORM_DATABASE =
TYPEORM_SYNCHRONIZE = true
TYPEORM_MIGRATIONSRUN = true
TYPEORM_LOGGING = true
TYPEORM_ENTITIES = src/**/**.entity.ts
#TYPEORM_ENTITIES = src/**/**.entity.js
TYPEORM_SUBSCRIBERS = src/subscriber/*.ts
#TYPEORM_SUBSCRIBERS = src/subscriber/*.js
TYPEORM_MIGRATIONS = src/database/migration/*.ts
TYPEORM_MIGRATIONS_DIR = src/database/migration
TYPEORM_SUBSCRIBERS_DIR = src/subscriber
Run code snippetExpand snippet
any help/hint is highly appreciated, thanks in advance.
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)