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.
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