尝试从节点js连接本地postgresql数据库

时间:2017-07-30 12:43:57

标签: node.js postgresql ionic-framework connection local

当我尝试发布帖子请求时,我得到的角色“用户名”不存在。然后我创建了一个名为“username”的角色并授予其权限。 现在我得到的错误是:

  

数据库“用户名”不存在。

connection informations

DATABASE_URL = postgres://postgres:1234@localhost:5432/mydb
  

错误:数据库“AGT”不存在    在Connection.parseE(C:\ Users \ AKT \ Desktop \ worldenglish \ worldenglish \ node_modules \ pg \ lib \ connection.js:539:11)       在Connection.parseMessage(C:\ Users \ AKT \ Desktop \ worldenglish \ worldenglish \ node_modules \ pg \ lib \ connection.js:366:17)       在Socket。 (C:\用户\ AKT \桌面\ worldenglish \ worldenglish \ node_modules \ PG \ lib中\ connection.js:105:22)       在emitOne(events.js:96:13)       在Socket.emit(events.js:189:7)       在readableAddChunk(_stream_readable.js:176:18)       在Socket.Readable.push(_stream_readable.js:134:10)       在TCP.onread(net.js:551:20)

//this is the node.js part
    app.post('/authOgretmen', function (request, response) {
      pg.connect(process.env.DATABASE_URL, function (error, client, done) {
        if(error) {
          console.log('wtf');
          response.send(error);
          throw error;
        }
        client.query('SELECT id,yetkiderecesi from ogretmenler where email = $1 and sifre = $2', [request.body.email, request.body.sifre], function (error, result) {
          console.log("girdi");
          if (error) {
            console.log("bb");
            response.send(error.message);
            done();
          }
          else {
            console.log("true");
            response.json(result.rows[0]);
            done();
          }
        })
      if(error) {
        response.send(error);
      }
      })
    });

//this is the ionic part
    karsilastirOgretmen(){
          this.http.post(this.url,{
          "email": this.email,
          "sifre": this.sifre
          })
          .subscribe(response => {
          this.id = response.json().id;
          this.yetkiderecesi=response.json()['yetkiderecesi'];
          this.navigateToOgretmenProfil();   
        });
      }

0 个答案:

没有答案