When you use the knex function to connect to a database, make sure you type your pgsql details when you created your database. Otherwise, it will give you errors like this one (no password provided):


Unhandled rejection error: password authentication failed for user "postgres"
at Connection.parseE (C:\Users\LENOVO\Desktop\smart-web-api\node_modules\pg\lib\connection.js:604:11)
at Connection.parseMessage (C:\Users\LENOVO\Desktop\smart-web-api\node_modules\pg\lib\connection.js:401:19)
at Socket.<anonymous> (C:\Users\LENOVO\Desktop\smart-web-api\node_modules\pg\lib\connection.js:121:22)
at Socket.emit (events.js:210:5)
at addChunk (_stream_readable.js:308:12)
at readableAddChunk (_stream_readable.js:289:11)
at Socket.Readable.push (_stream_readable.js:223:10)
at TCP.onStreamRead (internal/stream_base_commons.js:182:23)


const db= knex({
        client: 'pg',
        connection: {
          host : '127.0.0.1', //localhost
          user : 'postgres', //add your user name for the database here
          port: 3001, // add your port number here
          password : '', //add your correct password in here
          database : 'smartweb' //add your database name you created here
        }
});


See the Initializing the Library section here: https://knexjs.org/