0

I am writing here because I am trying to learn postgresSQL on NodeJS doing a todo list, but I have a problem when trying to send some request with Postman. I create an Express route, the database, the table and I'm trying to put my first task into my database, but when I try to send a post request with a body in Postman I have no response in Postman and in VS Code the terminal is asking me for a password, i did try the one from db.js, my postgres super user password, but nothing happen... I don't understand what to do.

Postman and VScode screenshot

I have this code :

index.js

const express = require("express");
const app = express();
const cors = require("cors");
const pool = require("./db");

// middleware
app.use(cors());
app.use(express.json());

//ROUTES

app.post("/todos", async (req, res) => {
  try {
    const { description } = req.body;
    const newTodo = await pool.query(
      "INSERT INTO todo (description) VALUES($1)",
      [description]
    );
    res.json(newTodo);
    console.log(newTodo);
  } catch (error) {
    console.error(error.message);
  }
});

app.get("/", (req, res) => {
  res.json("welcome");
  console.log("welcome");
});

app.listen(3001, () => {
  console.log("serveur as start on port 3001");
});

database.sql

CREATE DATABASE perntodo;

CREATE TABLE todo(
    todo_id SERIAL PRIMARY KEY,
    descritpion VARCHAR(255)
);

db.js

const Pool = require("pg").Pool;
const pool = new Pool({
  user: "postgres",
  password: "azerty",
  host: "localhost",
  port: 5432,
  database: "perntodo",
});

module.exports = pool;

zMzMTV
  • 1
  • 1
  • What is the actual prompt text for the password? Include in your question above. – Adrian Klaver Jan 09 '21 at 17:13
  • @AdrianKlaver The VS code terminal give me the information in french but it says something like : "authentification by password choose for the user of postgres : ". It's actually just asking a password, but when I put my known password for postgres or this database nothing happens, like litterally nothing – zMzMTV Jan 09 '21 at 17:29
  • @AdrianKlaver I added a link with a screenshot of my postman and vscode screen to be more understandable – zMzMTV Jan 09 '21 at 17:47
  • Can you login to postgres from the terminal with that password? – Abrar Hossain Jan 09 '21 at 17:53
  • What is listening on port `3001`? – Adrian Klaver Jan 09 '21 at 17:56
  • read this link i think helpful for your issue : https://stackoverflow.com/questions/7695962/postgresql-password-authentication-failed-for-user-postgres – mohammad javad ahmadi Jan 10 '21 at 08:03

0 Answers0