【发布时间】:2021-04-18 15:40:13
【问题描述】:
我正在使用 Typeorm 连接到数据库,但它无法连接并且没有显示错误。 如果我评论建立连接的行,一切正常。
这是我的代码
index.ts
import {App} from './app';
import { createConnection,Connection } from "typeorm";
import * as dotenv from 'dotenv';
import config from './ormconfig';
async function main() {
dotenv.config();
try{
await createConnection(config);
console.log('Connected to the database');
}catch(error){
console.log(`Error connecting to the database\n ${error}`.red);
}
const app = new App([
// new GrandTotalController()
// new AuthenticationController,
// new UserController(),
// new AccountMonthController
],
5000);
await app.listen();
}
main();
ormconfing.ts
import { ConnectionOptions } from 'typeorm';
import * as dotenv from 'dotenv';
dotenv.config();
const config: ConnectionOptions = {
type: 'postgres',
host: process.env.POSTGRES_HOST,
username: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASSWORD,
database: process.env.POSTGRES_DB,
port: Number(process.env.POSTGRES_PORT),
entities: [
__dirname + '/../**/*.entity{.ts,.js}',
],
migrations: [
'src/migrations/*.ts',
],
cli: {
migrationsDir: 'src/migrations',
},
};
export = config;
【问题讨论】:
标签: node.js typescript postgresql typeorm