I have encountered an issue while trying to incorporate TypeORM within a class. It seems to be unable to locate the default connection despite awaiting the connection. I have double-checked the configuration and tested it with .then(), which did work successfully.
class App {
public app: express.Application;
constructor() {
this.app = express();
this.connect();
this.test();
this.config();
this.routes();
}
private async connect(): Promise<Connection> {
return createConnection();
}
private async test(): Promise<User> {
const repository = getRepository(User);
const user = new User();
user.firstName = 'Daniell';
user.lastName = 'lastname';
return repository.save(user);
}
When calling the class:
import App from './App';
import { Server } from './Server';
(() => new Server(App))();
Any insights into why the default connection cannot be located?