Closed joetidee closed 7 years ago
Just realized that the reason I might be getting this error is because I am using the mongoose-seed package for trying to generate some fixtures prior to running some client-side mocha tests. Would you say this is the reason?
Hi Joe,
I think your intuition here is correct - the models are loaded from the path relative to where the module is being executed. Based on what you said you need to specify the path relative to your testing file.
Best, Sean
How can I use a file, that contains a seeder.loadModels
block, in two different locations across my application, if the paths have to be relative to the script that is including them?
The loadModels code is a wrapper around the path.resolve node.js method. You should be able to pass an absolute path to this without issue.
I am loading in models to the
seeder.loadModels()
function like so:The above path equates to /server/models/model.js, which seems like it should be correct. However, whe the function runs, it pukes:
Error: Cannot find module '/server/models/model.js'
so why is it not working?
(all paths below are relative to the applicaiton root) The model files are stored here
/server/models
The above loadModels function is being used in a file located here/seed/seed.js
Finally, seed.js is being imported into a file located here/client/tests/unit/globalBefore.js