Я не могу получить данные из PostgreSQL и отобразить их в node JS - PullRequest
0 голосов
/ 10 июля 2020

index.js

  const { Client }  =require('pg');
const client = new Client ({
user: 'postgres',
host: 'localhost',
database: 'test',
password: 'admin',
port: 5432,
}); 
client.connect();
module.exports.myconnection = client;

app.js

const express = require("express");
const port = 3000;
const app =express();
const db =require("./db");
app.use(express.json());
const interactrouter = require("./routes/interactions");
app.use("/data",interactrouter);
app.listen(port, () =>
console.log(`Server running at http://localhost:${port}`) // not single cotaions above tab 
);

interactions.js

const express = require ('express')
const router = express.Router()
const db =require('../db')
const { Client } = require('pg')
const client = new Client()

router.get('/',(req,res) => {
  client.query("SELECT id, decription, drugcode, diseasecode, type FROM interactions;")
.then (rows =>{
    console.log(rows);
    res.json(rows)
})
.catch(error => {
    console.log(error)
})

})
module.exports =router; 

моя проблема Я подключаюсь к серверу, но Я не могу получить данные из базы данных, и это мой код, как я могу это исправить, спасибо всем

так как я могу это исправить или что мне нужно отредактировать Я новичок в этом поле

...