You can try something like this.
In *~/projects/app/web.js:*
var mongoose = require('mongoose'), mymodule = require('mymodule');
mymodule.mongoose = mongoose.
// followed by configuration of the mongoose instance
In *~/projects/mymodule/index.js:*
exports.mongoose = null;
// needs to be the same instance of mongoose configured
by ~/projects/app/web.js
Just make sure you don't try to use mongoose before it is set up in
mymodule.
On Wednesday, 3 July 2013 05:29:51 UTC+2, [email protected] wrote:
>
> I am developing a module which requires access to the same cached version
> of a module (mongoose) that my main application uses.
>
> As explained by the docs, here:
> http://nodejs.org/api/modules.html#modules_addenda_package_manager_tips
>
> *...Node looks up the realpath of any modules it loads (that is, resolves
> symlinks), and then looks for their dependencies in the node_modules folders
> as described above...*
>
> In this case I have a directory structure:
>
> ~/projects/mymodule <- exposed using npm link
>
> ~/projects/app/web.js
> ~/projects/app/node_modules/mongoose
> ~/projects/app/node_modules/mymodule <- points to ~/projects/mymodule
> thanks to npm link mymodule
>
> In *~/projects/app/web.js:*
>
> var mongoose = require('mongoose'), mymodule = require('mymodule');
> // followed by configuration of the mongoose instance
>
> In *~/projects/mymodule/index.js:*
>
> var mongoose = require('mongoose');
> // needs to be the same instance of mongoose configured
> by ~/projects/app/web.js
>
>
> Because require() looks up the realpath of mymodule, it never finds the
> mongoose module installed in app.
>
> This is different from how it will behave in real-world usage (when
> mymodule is installed via npm).
>
> I understand this is a bit of a special case, in that I explicitly want
> the same version of a module in use by the main app, and never a specific
> one. I have not specified mongoose as a dependency of mymodule, and leave
> the author to ensure a valid, compatible version is required by the author
> of the app using mymodule.
>
> If there is a way to fix this (or a better structure), please let me know.
> To achieve what I am trying to do, it is crucial that the same instance of
> mongoose is shared between mymodule and the app.
>
> Thanks,
> Jed.
>
>
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.