Now, let's focus on what we have right now. After some refactoring before continuing with adding features. As you can see, we now use the EMP file to store even the server port. We are going to take back this info in the config.js file that we are going to import in the index.js file. We have now introduced our routes file to have some structure behind the roots of our web application, and to not have these routes hard coded in the index.js file. We are going to use it here right now in the app dot get function.
So after this little refactoring our articles class will contain methods to return the list of all the articles in our static list that returns a promise with the success response with the payload set to all the articles, then we have a function that will return the article indentified by an article id or an error if the article id does not match any article id. And after this refactoring our index.js file looks like this. So we are using routes that are not anymore coded. We are using the functions that will handle success response and error response, respectively, thanks to the definitions in the response management but what they will Like to I mean, I would like to focus on the introduction of body parser. We are not going to see the theory and the details, as I already said before, but what is important here is to understand is that for our past requests, we need the req dot body, dot body object, that by default, it's undefined.
And it's populated using body parser middleware, such as body parser. So thanks to body parser the req dot body object which contains key value pairs of data supplemented in the request body