evilcelery evilcelery - 1 year ago 147
Node.js Question

How can I share mongoose models between 2 apps?

I have 2 apps, each in a different folder and they need to share the same models.

I want to symlink the models folder from app A to a models folder in app B.

I'm running into issues with the fact that once you call mongoose.model('Model', Schema) in app A, they are 'tied' to that app's mongoose/mongodb connection.

Does anyone have any tips on the best way to manage this?

Answer Source

What I ended up doing here was importing app1 as a submodule (with Git) in app2. This way the models can be imported as normal and are tied to the app's default mongoose connection.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download