This is 2024. If you still have the same issue, your username should be the username of your cpanel account and the password should also be the password of your cpanel account.
import { DataSource } from 'typeorm';
import { DB_USER, DB_NAME, DB_PASSWORD, NODE_ENV, DB_TYPE, DB_PORT } from "./appconfig"
const AppDataSource = new DataSource({
type: DB_TYPE,
port: DB_PORT,
host: "localhost",
database: DB_NAME,
username: DB_USER,
password: DB_PASSWORD,
entities: [] // your entities,
synchronize: true,
logging: false,
});
AppDataSource.initialize()
.then(() => {
console.log('Database ::connected');
})
.catch((err) => {
console.error('Error during Data Source initialization:', err);
});