0
votes

I downloaded and installed postgreSQL on my windows machine, i also downloaded pgAdmin 4 for the user interface. I'm working on a node-js project But i can't connect to my database. I'm using knex, Here is my code

     const PORT = 3001;
     const bcrypt = require('bcrypt');
     const saltRounds = 10;
     const express = require('express');
     const bodyParser = require('body-parser');
     const cors = require('cors');
     const app = express();
     const knex = require('knex');

    const db = knex({
         client: 'pg',
         connection: {
             host : 'localhost',
             user : '',
             password : '',
             database : 'SmartBrain'
             }
   });

   db.select('*').from('users').then(resp => console.log(resp)); 

I'm getting this error :

app is running on port 3001
Unhandled rejection error: role "MostfaWindows" is not permitted to lo                        g in
    at Connection.parseE (C:\Users\MostfaWindows\Desktop\faceRecogniti                        onApi\node_modules\pg\lib\connection.js:553:11)
    at Connection.parseMessage (C:\Users\MostfaWindows\Desktop\faceRec                        ognitionApi\node_modules\pg\lib\connection.js:378:19)
    at Socket. (C:\Users\MostfaWindows\Desktop\faceRecognit                        ionApi\node_modules\pg\lib\connection.js:119:22)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)
    at TCP.onread (net.js:594:20)

"MostfaWindows" is my computer name. Any help would be much appreciated, thank you.

1
Your configuration for connecting to Postgres is incorrect. Check the values for localhost, the database port, the database user and the database password. - laaksom
In my pgAdmin i have this URL, should i put this instead of localhost? "127.0.0.1:65480/browser" - Mustapha Gheribi
What is the user for your PG db? - Jason Kim

1 Answers

1
votes

I solved the problem by simply creating a user, granting it select priviliges and putting the user name in the user field in connection.