node server can't connect to postgres db

前端 未结 2 1252
一生所求
一生所求 2021-01-05 10:52

I recently switched from MySQL to postgres as my database for an node.js project. While I\'m able to reach my remote postgres database from my local pgAdmin III (OSX) client

相关标签:
2条回答
  • 2021-01-05 11:32

    The interface in node.js that I used can be found here https://github.com/brianc/node-postgres

    var pg = require('pg');
    var conString = "postgres://YourUserName:YourPassword@localhost:5432/YourDatabase";
    

    try changing pg:// to postgres://

    This was scraped from another stackoverflow article: How to make connection to Postgres via Node.js

    0 讨论(0)
  • 2021-01-05 11:36

    It appears that node-postgres doesn't accept a hashtag in your password. After removing the hashtag I was able to connect without a problem. Wouldn't have thought of that and it didn't strike me as a problem since pgAdmin accepted it.

    The best solution would be to use encodeURIComponent to encode your password string. This would allow for hashtags to be used in the URL.

    0 讨论(0)
提交回复
热议问题