Michael Jay
Michael Jay

Reputation: 593

Can't authenticate user with Knex.js migrate:latest in Node

The problem:

Relevant information: Windows 10, Node, knex, PostgreSQL

I'm trying to run the knex CLI command migrate:latest from cmd, knex migrate:latest --env development.

I'm getting "error: password authentication failed for user "

My first problem is with the user specified - in my knexfile.js configuration file, I am exporting the development object with a defined connection, where all of my environment variables are defined.

  development: {
    client: 'pg',
    connection: {
      host: "localhost",
      port: process.env.DB_PORT,
      username: process.env.DB_USER,
      password: process.env.DB_PW,
      database: process.env.DB_NAME
    }
  }

So although I'm trying to log into the DB as 'postgres', knex is trying to log me in as the Windows user from the associated error message, which is my only account on my personal computer. I am logged in as that user, PostgreSQL was installed with this user account, and the database was initialized with this user.

Using psql, I can log into the database specified in my knex config using the password specified in my knex config. In fact, I'm using the same password for all users to reduce the number of variables in my problem.

In addition to trying to solve the problem this way, I have all of my authentication settings in my pg_hba.conf file set to 'trust' - but that isn't fixing the problem either.

Upvotes: 1

Views: 1332

Answers (1)

Mikael Lepistö
Mikael Lepistö

Reputation: 19718

Try to hardcode username and password and DB name to knexfile instead of using process.env.XXXX and try again.

Sounds like your environment variables are not passing to the node correctly.

Upvotes: 1

Related Questions