From the course: Learning Node.js

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Async/await

Async/await - Node.js Tutorial

From the course: Learning Node.js

Start my 1-month free trial

Async/await

- [Instructor] Asyncawait is one of the latest features to make it into Node. Similar to promises, it makes a synchronous code look even more synchronous. In order to work with await, we will need to declare our express function as async. So on line 27, in the second parameter where we specify our callback, let's add async. At this point, we can use await on message.save, which will return a value once it finishes and will save it into a variable called savedMessage. So on line 30, I'll create savedMessage and set it to await message.save. Now I can get rid of this then call and I can simply call our console log to show that it'll save. Next we'll do the same for our censored words. So I'll create a censored variable and set it to message.findOne, as we check for our bad word. And, again, I can get rid of this then in the callback. Then we just check if there was a censored word. We'll display it in our console log and we'll remove it. And, again, we'll use await and we'll replace…

Contents