首页 > 解决方案 > '错误:Node.js 中的数据库“根”不存在'

问题描述

我正在运行与 Postgres 数据库对话的 NodeJS 微服务。但是当我尝试启动服务时,我遇到了错误。我不知道为什么会弹出这个错误。

错误:

   UnhandledPromiseRejectionWarning: Unhandled promise rejection(rejection id:1): error: database “root” does not exist

我的数据库连接详细信息:

  const pg = require(“pg”);
  const client = new pg.Client({
            host: “txslmxxxda6z”,
            user: “mom”,
            password: “mom”,
            db: “mom”,
            port: 5025
  });

标签: node.jspostgresqlpg

解决方案


我能够自己解决这个问题。问题出在连接配置中。它应该是数据库而不是数据库,所以这是导致问题的原因。PFB 答案

 const client = new pg.Client({
        host: “txslmoxxx6z”,
        user: “mom”,
        password: “mom”,
        //change db to database
        database: “mom”,
        port: 5025
 });

推荐阅读