Using Node’s file system API, Scott demonstrates how to consume a Node-style callback as a promise. He wraps the API call in a native promise and returns a call to the resolve or reject methods.
(gentle music)…- So, that's like the basics of a promise.…So, this is how you would make a promise.…Now, how you would consume a promise…is that, again, because…Node has its convention of the Node style callbacks,…where everything is error response.…So what we'll do is,…let's refactor a common function…that you would see in Node.…Something like reading the file system.…So what we'll do is we'll save…our file system equals require file system.…
And what we'll do is we'll start off…reading the package dot JSON.…Alright, you got a question?…Okay, you stretching, alright.…So, we'll say fs.readFile.…And, we'll say package.json.…So, read this file, it takes a callback.…Node style callback, which means it's error…and then, the data that you want.…I'm going to call that file.…So this is asynchronous.…This doesn't happen synchronously, right?…So this is going to happen in the future.…
Does everyone know what I mean when I say that?…Like if I put a console.log underneath this,…just to show you.…After read file.…I'm just going to get rid of all this stuff…
This course was created by Frontend Masters. It was originally released on 12/30/2015. We're pleased to host this training in our library.
- Executing Node.js
- Using Express
- What is middleware?
- Testing in Node.js
- Using Mongo with Node.js
- Data modeling
- Querying data with Mongoose
- Identifying sensitive routes
- Configuring the deployment
Skill Level Intermediate
Node.js: Build Your First Microservicewith Daniel Khan2h 9m Intermediate
Building APIs Using Hapi in Node.jswith Kirsten Hunter2h 23m Intermediate
2. REST APIs
5. Organization and Configuration
7. Data Modeling
10. Securing Routes
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.