Join Alexander Zanfir for an in-depth discussion in this video Creating a custom promise, part of Learning Node.js.
- We learned how promises can help clean up your code,…but how do they actually work?…In the last example,…we auto-generated promises from the file system package.…This time let's create our own.…We'll start by creating a new file for this exercise.…And we'll call is promise demo.js…For this example I wont be using bluebird…since it's very simple.…And instead I'll be using the native promise library.…This promise library does not need a require.…And it has the same functionality…for creating your own promises as bluebird.…
So we'll start by creating a variable called promise.…And we'll set it to a reference of a new promise.…And in here we'll supply a callback.…Every promise object expects a callback…with a resolve and reject parameter.…So let's go ahead and supply that.…And if we call resolve right away…the promise will return a then object.…So if we type in promise.then…the callback should execute.…
So we can test that by doing a simple console.log…And we'll supply then as the text.…Let's give that a try and run that.…
- Installing Node.js
- Writing modules and packages
- Reading and writing files
- Working with frameworks: Express, Sails, and Koa
- Generating promises
- Working with generator functions
Skill Level Beginner
Q: When I try to install Bluebird/Express/Gulp/Sails/KOA using the Node Package Manager, it seems to install correctly in the terminal. But why doesn't my project folder change?
A: You need to make sure that you've navigated to your project folder in the terminal. For example, in this course Alexander is working from the C:\Dev\ folder both in Brackets and in the terminal.