-1

I have a few Node apps, each hosted in a different container (Heroku dyno). All the apps use the same mongo models, so when I change a model, I have to change it for each app. I was wondering if there is a way to share the model files among all my apps.

I thought about hosting the model files in a different container, and then making them available to the apps, but I'm not sure how to do it.

A little more generally speaking, how can I share JavaScript files among different containers / servers? Is that the best approach to solve this problem?

Thanks!

John
  • 3
  • 1
  • I think you have a repo to contain all mongodb models. whenever update that repo you can trigger a build for depending repos – duc mai May 28 '19 at 19:04

1 Answers1

0

First put your common model code into a local npm module as in Installing a local module using npm? then build and deploy your images as normal.

Wyck
  • 10,311
  • 6
  • 39
  • 60
  • I'd like to answer that, but..."Other people?" I thought this was a code issue. What do you mean "other people get the updates"? Maybe your original question should have had more details. I assume docker is involved here right? Do you mean to modify a file and then have containers on multiple servers pick up the changes without rebuilding and re-deploying the containers? – Wyck May 28 '19 at 19:16
  • I am sorry if my question wasn't clear. Suppose I am developing a new feature, which requires me to modify a model. Right now, I have to load each of my app projects, change the model and push it, which is kinda annoying. So, I am trying to find a way so that when I make a model change in a particular project and push it, the change is automatically applied to the other apps which use the same model. – John May 28 '19 at 19:57
  • It seems I can crate a npm module, as you suggested, host it on a git repo, and then make it a dependency on all of my app projects. – John May 28 '19 at 20:41
  • Not 100% clear if you are willing to rebuild docker images and redeploy to achieve this, or if you are looking for a run-time solution. I was originally just describing how to set up a code dependency. I assumed you would rebuild docker images and redeploy apps when you make a change. – Wyck May 29 '19 at 15:31
  • You don't need to host the shared npm module anywhere special. Just use files relative to your app directories. If you have `/myproject/myapp1/package.json` and `/myproject/myapp2/package.json` you can create `/myproject/sharedstuff/package.json` and from /myproject/myapp1/ do `npm install ../sharedstuff` then repeat for myapp2. The link I provided describes details of how. Again, assuming you are willing to rebuild and redeploy when you make code changes to your model (shared or otherwise). Correct me if I'm wrong. – Wyck May 29 '19 at 15:32
  • The problem is that I don't have `/myproject/myapp_x` structure. Each app is in a different project folder. Moreover, some apps are hosted on Heroku and some on AWS. It wasn't me who set them up this way. Given the circumstances, I think I do need to store the npm module in a special place. – John May 30 '19 at 13:57