0

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.

3
  • Your configuration for connecting to Postgres is incorrect. Check the values for localhost, the database port, the database user and the database password. Commented Jul 17, 2018 at 3:22
  • In my pgAdmin i have this URL, should i put this instead of localhost? "127.0.0.1:65480/browser" Commented Jul 17, 2018 at 3:23
  • What is the user for your PG db? Commented Jul 17, 2018 at 3:31

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.