From the course: Building a Website with Node.js and Express.js

Unlock the full course today

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

Storing data

Storing data

From the course: Building a Website with Node.js and Express.js

Start my 1-month free trial

Storing data

- [Instructor] All that is left for a working feedback page is calling the respective function to write the user-provided feedback to a file. Let's look into the feedback service for that. So I open services, feedbackService, and when I scroll down, I see a function, a method addEntry. So that's exactly what we need here. It just updates the feedback with a new entry. And if you wonder what this data.unshift is, this is used to prepend something to an array. Otherwise we could push it, but then new feedback items would appear in the end, which is a little bit counterintuitive. Let's go back into a feedback route, and of course we have to add this to the post request so after the validation did run and we check for the errors, if we end up down here, we are sure that the data we got is valid. Now I can just add await feedbackService.addEntry. Now I have to do two things, first of all I have to make this callback async…

Contents