Share npm packages between the meteor app bundle and other node.js apps

My meteor.js web server runs in an ARM-based device. Now comes a new non-web node.js app which share many npm packages used in the web server. In the development mode, I thought about using npm-link to organize the sharing of npm packages between the meteor app and the node app. But for production, the bundling of the meteor app has its own plan of installing the npm packages. What is the correct way to share npm packages between the meteor app bundle and other node.js apps, or is it possible at all?

In our system, our Meteor server also shares numerous npm packages with various non-web Node.js apps – we don’t have ARM devices though. Meteor has its own package.json, so do our Node.js apps, and, as required by each of those apps, be it Meteor or Node.js, we simply install the packages via npm.

The deployment procedures differ a lot from one another, but your question was only how to share npm packages. During deployment the packages get installed both for the Meteor server, as for each individual Node.js app. We didn’t run into any difficulty at all.

peterkruger, thanks for your sharing

In our system, our Meteor server also shares numerous npm packages with various non-web Node.js apps – we don’t have ARM devices though. Meteor has its own package.json, so do our Node.js apps, and, as required by each of those apps, be it Meteor or Node.js, we simply install the packages via npm.

Maybe I did the same for the directory layout of my meteor and node apps:

+meteor
    +dev_bundle
        +lib
             +node_modules
+my-meteor-app
    -package.json
    +node_modules
+my-node-app
    -package.json
    +node_modules

For my-meteor-app:

     meteor/dev_bundle/lib/node_modules is for global packages
     my-meteor-app/node_modules is for local packages

For my-node-app:

    my-meteor-app/node_modules is for global packages
    my-node-app/node_modules is for local packages

This arrangement worked for development mode, where the directory layout is as described above. But when bundling for deployment, each app bundles the global packages for itself, as it would:

+ my-meteor-app-bundle
    +program
         +server
               +npm
                     +node_modules

+ my-node-app-bundle
      ... (the bundle tool is not yet decided)
            + node_modules

For an embedded device, another copy of 100M is just too much. Moreover, my-meteor-app and my-node-app should really share these dependencies (use same package versions).

The deployment procedures differ a lot from one another, but your question was only how to share npm packages. During deployment the packages get installed both for the Meteor server, as for each individual Node.js app. We didn’t run into any difficulty at all.

As I understood, your deployment installed the same dependencies in different locations? This is half of my target. The other half is for the 2 bundles to share the same node_modules directory. I wonder if it is possible at all and if it is somehow possible, what trouble I may run into for future development / maintenance?

Now I begin to understand what you meant with “share npm packages”. Until now I mistakenly believed that sharing has meant “using the same packages”, as in “both app1 and app2 to use package p1”. Which is as easy as npm install p1 both for app1 and app2 individually.

But in fact you want to use the same files and directories where those packages are installed, in order to save space on the ARM device. I’m sorry, I have no idea how to do that.

1 Like

I thought about directly using
my-meteor-app-bundle/server/npm/node_modules
for my-node-app, which is sofar not bundled and is more flexible about where the global node_modules is. I guess this should work, especially because my-node-app is server side only. Just would like to poll if somebody faced the same situation and had a better idea.