连接Postgres和Node应用程序,使用knex.js在fly.io上。

huangapple go评论62阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年7月17日 08:49:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76700956.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定