admin管理员组文章数量:1122846
I am trying to set up a PostgreSQL database connection with TypeORM in my Next.js project using a DATABASE_URL
string, but I'm facing issues getting the connection to work.
My current TypeORM setup (data-source.ts
):
import { User } from "@/entities/User";
import "reflect-metadata";
import { DataSource } from "typeorm";
export const AppDataSource = new DataSource({
type: "postgres",
host: process.env.DB_HOST,
port: parseInt(process.env.DB_PORT || "5432", 10),
username: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
entities: [User],
synchronize: true, // Set to false in production
logging: true,
});
I would like to refactor my data-source.ts
to directly use the DATABASE_URL
string, so I don’t need to manage separate environment variables for host, port, username, etc. I want TypeORM to automatically parse the DATABASE_URL
connection string for me.
My error:
Starting DB inilize!
⨯ error: no pg_hba.conf entry for host "119.xx.xxx.xx", user "postgres", database "postgres", no encryption
at Socket.emit (node:events:514:28)
本文标签: How to connect TypeORM to PostgreSQL using a DATABASEURL connection string in NextjsStack Overflow
版权声明:本文标题:How to connect TypeORM to PostgreSQL using a DATABASE_URL connection string in Next.js? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736304526a1932267.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论