Search code examples
node.jsexpressnode-postgres

UnhandledPromiseRejectionWarning: error: permission denied for table


I'm building a node express web application that interfaces with a postgres database using node-pg. In my local environment everything runs fine but when I pull the project from github on a different machine and try to run it I get the following error: (node:445) UnhandledPromiseRejectionWarning: error: permission denied for table <some table>

I'm not sure why I'm getting this error as I am connecting to the same database with the same credentials as from the local environment, and I've tried to make sure the proper privileges are granted by using the command GRANT ALL PRIVILEGES ON TABLE <some table> TO postgres; and then restarting the database service.

Is there something I'm missing or how would I go about solving this issue?


Solution

  • While I can't suggest an overall fix for your connection issues we can fix the UnhandledPromiseRejectionWarning by literally handling the Promise rejection.

    try {
      // connect to pg
    }
    catch(e) {
      console.error(e)
      // Probably if you can't connect to the DB at all that's an unrecoverable problem.
      // I'd log whatever useful stats about the running application as you can and then maybe just end the process.
      process.exit(1)
    }
    

    Note the docs for process.exit() though, that "This means that any callback that's pending, any network request still being sent, any filesystem access, or processes writing to stdout or stderr - all is going to be ungracefully terminated right away." which may or may not be a problem for you.