我在命令行上使用knex迁移来设置我的postgresql数据库(如果它有任何区别,则在Windows上)。到目前为止,我能找到给knex用户名/密码到postgres数据库的唯一选择是把它放在knexfile中。
我宁愿在knexfile中没有明文密码。
答案 0 :(得分:1)
通常,您可以在knexfile.js
内的环境变量中读取密码和其他连接设置,如下所示
module.exports = {
client: 'postgres',
debug: false,
connection: {
host: process.env.POSTGRES_HOST || 'localhost',
port: process.env.POSTGRES_PORT || 5432,
user: process.env.POSTGRES_USER || 'postgres',
password: process.env.POSTGRES_USER_PW || undefined
}
};