Reputation: 31
I am trying to implement an auth service using node-express-postgres.
I had the pool configed as such:
const Pool = require('pg').Pool;
const pool = new Pool({
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
host: process.env.DB_HOST,
port: 5432
});
module.exports = pool;
I am trying to do the following call as a simple test for connection:
const express = require('express');
const router = express.Router();
const pool = require('../db');
const bcrypt = require('bcryptjs');
router.post('/login', async (req, res) => {
try {
let temp = await pool.query("SELECT * FROM records");
console.log(temp)
} catch (error) {
console.log(error.message);
}
});
When I send a post request to this endpoint my app crash with the following error:
Error: SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string
I have checked all my env vars and they are correct. Any idea why it is failing to do any operation on the postgres DB?
Upvotes: 3
Views: 17187
Reputation:
Check out the path in your IDE folder, when i checked, it was by one path below, so i moved it in the correct folder and boom, it all worked.
Upvotes: 0
Reputation: 1
Fixed it by updating npm script.
cross-env NODE_ENV=development nest start
Installed "cross-env" to set NODE_ENV. If our code is not able to find .development.env file or unable to find password, then this error will be thrown.
Upvotes: 0
Reputation: 654
you probably should indicate your .env file location inside of the config
require('dotenv').config({ path: '../.env' });
Upvotes: 0
Reputation: 244
Check your postgres password if it's correct. I had a similar problem while working on a mac, by default the posgreSQL user is "posgres" and password is "root"
In my case I had something like
...
USER: "postgres",
PASSWORD: "",
...
which generated the error
Upvotes: 1
Reputation: 141
It seems, that node didn't read .env file. You can check it with
console.log(process.env.DB_PASSWORD);
It can be fixed with package 'dotenv', for example.
npm i --save dotenv
And then in first line in index.js
require('dotenv').config();
Upvotes: 8