pg.connect not a function?

后端 未结 4 1726
梦谈多话
梦谈多话 2021-01-17 07:59

There appears to be a lot of documentation (e.g. https://devcenter.heroku.com/articles/heroku-postgresql#connecting-in-node-js, but also elsewhere including this site) indic

4条回答
  •  醉梦人生
    2021-01-17 08:40

    var express = require('express');
    var app = express();
    const pgp = require('pg-promise')();
    var connectionString = "";
    var parse = require('pg-connection-string').parse;
    
    try {
        var connectionString = "postgres://USERNAME:@localhost:5432/DBNAME";
        var config = parse(connectionString);
        config.password = "PASSWORD";
        var dbcon = pgp(config);
        app.set('dbCon', dbcon);
    } 
    catch (error) {
        console.log("DB error")
    } 
    

    module.exports = app;

提交回复
热议问题