0

Im currently trying to export a model on nodejs using thinky(rethinkdb orm). I separate my models in different files for more clarity. The pattern goes likes this.

var modelA = think.createModel ... 
//API methods   
exports.list = ...
exports.add = ...
exports.delete = ...
exports.update = ...
exports.get = ...
exports.model = modelA

On my app.js (main file) everything works great but when on modelB I want to export the require statement returns an empty object.

This is bugging me.

Diego Gallegos
  • 1,722
  • 2
  • 18
  • 31
  • Have you read [Michel's article](https://thinky.io/documentation/architecture/) on the issue? – Tholle Feb 29 '16 at 21:49
  • Yes I have. The only difference is I use exports rather than using module.exports. Ive read several articles regarding it but I can't understand. What I dont understand is why from one file everything seems to work ok but from another it justs returns an empty object. – Diego Gallegos Feb 29 '16 at 22:25
  • Your last line is just `export`. Try `exports` as you've done earlier. – Tholle Feb 29 '16 at 22:31
  • @Tholle I already modify the post, sorry that was a typo on the question. Yes I have read the article but I they use module.exports instead of exports, Im not very clear on the usage of it. – Diego Gallegos Mar 01 '16 at 14:44
  • Would you explain how to use module.exports instead of exports on this example where there are 4 functions and 1 model exported? – Diego Gallegos Mar 01 '16 at 15:15
  • There's no difference, so I don't think that is your problem. Sorry. – Tholle Mar 01 '16 at 15:16
  • Not an answer to your specific questions so I'll just put it as a comment but you can also use [thinky-loader](https://github.com/mwielbut/thinky-loader) to make importing and sharing dependent models a bit easier. – Matt Wielbut May 18 '16 at 11:22
  • This my be way off, but have you tried using exports.modelA = modelA and exports.modelB = modelB ? – alex Jul 23 '16 at 08:07

0 Answers0