Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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;

question from:https://stackoverflow.com/questions/65645050/postgresql-is-asking-for-a-pasword-when-doing-request-with-postman

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
221 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...