kev*_*vin 2 javascript express pg-promise
我正在尝试将我的文件从使用pg包更改为pg-promise包。我使用的初始解决方案一切正常pg。但是,切换到pg-promise并使用文档后,我在设置过程中遇到了奇怪的错误。
最新错误:
throw new TypeError('Invalid "options" parameter: ' + JSON.stringify(options));
^
TypeError: Invalid "options" parameter: "postgres://me:complete@localhost:5432/education_be"
Run Code Online (Sandbox Code Playgroud)
我的配置文件:
require('dotenv').config();
const pgp = require('pg-promise');
// === My initial setup just using 'pg'
// const { Pool } = require('pg');
// const pool = new Pool({
// name: process.env.name,
// password: process.env.password,
// host: process.env.host,
// database: 'education_be',
// port: process.env.port
// });
// === My first attempt following the guide would receive errors like:
// === Error: Option "user" is not recognized.
const connection = {
name: 'me',
password: 'password',
host: 'localhost',
database: 'education_be',
port: 5432
};
// === attempting (unsuccessfully) to just use the address
const db = pgp('postgres://me:complete@localhost:5432/education_be');
module.exports = db;
Run Code Online (Sandbox Code Playgroud)
小智 9
我迟到了,但希望这可以帮助遇到同样问题的其他人。尽管您没有任何选项,但您必须在 pg-promise require 语句中包含括号。
const pgp = require('pg-promise')();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2959 次 |
| 最近记录: |