英文:
Connecting Postgres and Node App with fly.io using knex.js
问题
Has anyone tried deploying postgres and node app with fly.io using knex?
我想知道连接字符串是什么:
knex({
client: "pg",
connection: {
host: process.env.DATABASE_URL,
},
});
连接字符串是什么?
英文:
Has anyone tried deploying postgres and node app with fly.io using knex?
I am trying to figure out what the connection string would be:
knex({
client: "pg",
connection: {
host: process.env.DATABASE_URL,
},
});
What would be the connection string be?
答案1
得分: 0
当您在使用knex
与Postgres数据库时,DATABASE_URL
环境变量通常是包括用户名、密码、主机、端口和数据库名称的连接字符串。
postgres://username:password@localhost:5432/mydatabase
在knex
配置中,您可以简单地将此DATABASE_URL
提供为连接。Knex可以直接解析连接字符串:
knex({
client: 'pg',
connection: process.env.DATABASE_URL,
});
在fly.io
的上下文中,通常会在您的Fly.io应用程序配置中将DATABASE_URL
作为环境变量设置获取。
英文:
When you're using knex
with a Postgres database, the DATABASE_URL
environment variable is typically a connection string that includes the username, password, host, port, and database name.
postgres://username:password@localhost:5432/mydatabase
In the knex
configuration, you can simply provide this DATABASE_URL
as the connection. Knex can parse connection strings directly:
knex({
client: 'pg',
connection: process.env.DATABASE_URL,
});
In the context of fly.io
, you'd generally obtain your DATABASE_URL
as an environment variable set within your Fly.io application configuration.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论