More2Life / m2l-server

More2Life App Server
https://m2l-server.herokuapp.com
2 stars 0 forks source link

Refactor feedItems endpoint to put logic in controller. #25

Closed dodgertodd closed 7 years ago

dodgertodd commented 7 years ago

I'm pretty sure this is functionally equivalent. @kingbrendann please checkout and run it for me, however you've been testing it? Also please see how I call module.exports to export feedItemController, whereas you were using exports.[modelName]. I don't know which is right. I thought maybe you had a mongoose reason for doing it that way.

kingbrendann commented 7 years ago

exports is a convenience object that simply references module.exports. I used exports.[modelName] for clarity.

exports.[modelName] = foo var foo = require(./path/to/file.js).modelName

Is the same as

module.exports = foo var foo = require(./path/to/file.js)

The first is slightly more verbose but a lot more clear IMO. That pattern also allows you to export and name multiple objects or functions. In that case we could also do:

module.exports = { modelName: model someFunction: function(){} }

I just think the exports.modelName pattern is more clear.