Join Alexander Zanfir for an in-depth discussion in this video Callbacks versus generators, part of Learning Node.js.
- Let's create a generator function that will…read a file in order to compare callbacks to generators.…And just like the standard file system…library did not work with promises,…it will not work with generators as well…so we must use a wrapper called co-fs.…Let's begin by installing that.…We'll go over to our console or terminal…and npm install co-fs.…Next, let's create a new exercise file.…We'll call this generators-vs-callbacks.js.…
And we'll begin by requiring in the new file system.…Which in this case will be co-fs.…With this new library…we are now able to use yield…with the readFile function.…We also need to bring in one more library…and this is what will start our generator function.…Since we don't want to manually call next in a loop.…That library is called co.…Let's go ahead and install that now.…
And let's require it in.…And all we need to do is wrap…our generator function with co.…And that will control its execution.…So we'll define our generator function as the parameter.…And now let's create a variable to…
- 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.