You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{Client}from'pg';constclient=newClient({host: 'ec2-54-204-40-121.compute-1.amazonaws.com',port: 5432,user: 'otacrrqnhvxubd',password: 'fd33f58e8a039bc5b4abc0deea60f30b3fc531e453fad8aac592a775cc27c7be',database: 'delgu0put0dajp'});asyncfunctionmain(){try{awaitclient.connect();}catch(error){console.error(error);}try{constres=awaitclient.query('SELECT $1::text as message',['Hello world!']);console.log(res.rows[0].message);}catch(error){console.error(error);}try{awaitclient.end();}catch(error){console.error(error);}}main();
报错:
error: no pg_hba.conf entry for host "155.201.35.107", user "otacrrqnhvxubd", database "delgu0put0dajp", SSL off
at Connection.parseE (/Users/ldu020/workspace/nodejs-pg-knex-samples/node_modules/pg/lib/connection.js:554:11)
at Connection.parseMessage (/Users/ldu020/workspace/nodejs-pg-knex-samples/node_modules/pg/lib/connection.js:379:19)
at Socket.<anonymous> (/Users/ldu020/workspace/nodejs-pg-knex-samples/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:597:20)
本项目使用的
PostgreSQL
RDBMS
部署在Heroku
上,软件服务链接: https://www.heroku.com/postgres使用node-postgres本地开发时,链接远程数据库服务代码如下:
报错:
查看文档可知,外部网络要链接到
heroku
上部署的PostgreSQL
数据库服务,需要设置sslmode=require
,修改后的代码如下:再次执行代码:
The text was updated successfully, but these errors were encountered: