Hi team,
I have some suggestions/comments about the file /controllers/collaborators.js:
Name
collaborators.js is not representing the content as we are managing the api responses.... So I suggest to rename it to api.js
Responses & Scenarios
This is just an example from the current file:
function getCollaborators(req, res){
fs.readFile('./collaborators.json', 'utf8', (err, data) => {
if (err) {
return res.status(400).send(err)
}
res.status(200).send(data)
})
}
The functionality is perfect, but I have some suggestions:
HTTP wrong status code
Code 400 (Bad Request) is not applicable in this scenario as the error is generated by the server in order to retrieve the information from a local file. My suggestion is to use 500 (500 Internal Server Error). You can check the full list here.
Choose the right Response method
In order to avoid any issue with json formats... Express provides an special method for managing json responses, res.json()
Note: This will be relevant when the database is ready to serve the data.
200 status by default
By default express use 200 status code, so there is no need to add it manually.