我正在部署一个将postgresql数据库连接到heroku的应用程序nodeJS,但我不知道该怎么做。
index.js-通过端口8888连接到数据库
var express = require('express');
var app = express();
app.use(express.static("public"));
app.set('view engine', 'ejs');
app.set("views", "./views");
app.listen(process.env.PORT || 3000);
var pg = require('pg');
var config = {
user: 'postgres',
database: 'book',
password: 'hovupham0311',
host: 'localhost',
port: '8888',
max: 10,
idleTimeoutMillis: 30000,
}
var pool = new pg.Pool(config);
app.get("/",function(req,res){
pool.connect(function(err, client, done) {
if (err) throw err
client.query('SELECT * FROM sach', function(err, result) {
done();
if (err) {
res.end();
return console.error(err);
}
res.render("home",{data:result});
});
});
})
这是package.json文件
{
"name": "demo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"ejs": "^2.7.1",
"express": "^4.17.1",
"multer": "^1.4.2",
"pg": "^7.12.1"
}
}
,一切都可以在本地主机上运行。有人可以帮我吗!