Faced the problem when developing a database with requests to Node.js + PostgreSQL, when I make a request to Postman without interacting with the database, but simply outputting into the console, everything works, as I try to make a POST request to the database immediately flies out this Error
(Node: 692) unhandledpromiserejectionwarning: unhandled promise rejection. This error originated either by Throwing Inside An Async Function Without A Catch Block, Or by Rejecting a Promise Which Was Not Handled with .catch (). To Terminate The Node Process On Unhandled Promise Rejection, Use The Cli Flag
- Unhandled-Rejections = Strict
(See https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode ). (Rejection ID: 1)
(Node: 692) [DEP0018] DeprecationWarning: Unhandled Promise Rejections Are Deprecated. In The Future, Promise Rejections That Are Not Handled Will Terminate The Node.js Process With A Non-Zero Exit Code. “*
const db = require ('../ db');
Class PostController {
ASYNC CREATEPOST (REQ, RES) {
Console.log (REQ, RES);
const {title, message, image, likescount} = REQ.BODY;
Console.log (Title, Message, Image, LikeScount)
const newpost = await db.query ('Insert Into Posts (Title, Message, Image, Likescount) Values ($ 1, $ 2, $ 3, $ 4) Returning *', [Title, Message, Image, LikeScount]);
res.json (NEWPOST);
}
ASYNC GetPosts (Req, Res) {
}
ASYNC Getonpost (Req, Res) {
}
ASYNC UPDATEPOST (REQ, RES) {
}
Async Deletepost (REQ, Res) {
}
}
module.exports = new postcontroller ()
Answer 1, Authority 100%
This is not a problem Node + PostgreSQL.
Run such code in Node …
async function foo () {
THROW NEW ERROR ('ERROR')
}
Void Async FUNCTION () {
Const Bar = await foo ()
Const Data = Bar.json ()
} ()
… and see the same mistake.
foo (): Promise
ended with an error that needs to be processed. In this example, use try / catch
.
You will have to rummage in the code and find this most unresolved Promise
.
Yes, here they are Promise
.