Home node.js Error Unhandled Promise Rejection Node.js

Error Unhandled Promise Rejection Node.js




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 {
    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 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 () {
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 .

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions