Nodejs - Connect MongoDB with Node app using MongooseJS, Data Structures and Algorithms – Self Paced Course, Ad-Free Experience – GeeksforGeeks Premium, More related articles in Web Technologies, We use cookies to ensure you have the best browsing experience on our website. The goal of this article is to introduce CommonJS promises as they exist in NodeJS user-land. Yet, raw callbacks sacrifice the control flow, exception handling, and function semantics that developers are familiar with in synchronous code: Promises offer a way to get that control back with: Still, promises can be confusing, so you may have written them off or skipped directly to async/await, which adds new syntax to JavaScript for promises. Finally, throughout the article, I compare the use of promises to the more traditional use of callbacks for implementing asynchronous tasks in JavaScript. This module is only available on Node.js from version 8 onwards. Therefore, I would like to write down the way I understand promises, in a dummy way. The Promise class has been included in Node.js since v4.0.0. How to set the default value for an HTML