0

Can someone please tell me what the recommended way to use a node.js package that one would install with npm locally (npm without -g option)?

One way someone recommended was:

    % cd myapp/.meteor/local/build/server/
    % npm install aws-lib
    npm http GET https://registry.npmjs.org/aws-lib
    npm http 304 https://registry.npmjs.org/aws-lib
    npm ERR! Could not create /home/user/myapp/.meteor/local/build/server/node_modules/___aws-lib.npm

This fails because myapp/.meteor/local/build/server/node_modules is symlinked to /usr/lib/meteor/lib/node_modules/.

I want to install it locally for a several reasons. I want it to be portable as in, if I deploy the app somewhere else, I want all the dependencies to travel with it. I don't want to do this as root. It seems wrong to install stuff like this into /usr/lib/meteor.

Michael Grant
  • 320
  • 2
  • 8

1 Answers1

0
  1. First, meteor bundle bundle.tar.gz to get a node-deployable package of your app.
  2. tar -xvf bundle.tar.gz and cd bundle.
  3. In the bundle's server directory there is a node_modules directory.
  4. cd server & npm install aws-lib

This is a deployment-ready package. Call node bundle/main.js to start it.

To actually use the module, you will have to call __meteor_bootstrap__.require.

Checkout this for a more detailed solution! https://stackoverflow.com/a/12730509/1757994

Alternatively, you can wrap the node module as a package that includes the module's code and the __meteor_bootstrap__.require line. This is a good example of a simple shim:

https://github.com/tmeasday/meteor-page-js

And this is an example of a shim around a node module:

https://github.com/possibilities/meteor-awssum

I suspect this is the package you wanted in the first place...

Community
  • 1
  • 1
DoctorPangloss
  • 2,994
  • 1
  • 18
  • 22
  • The problem I see with this is that you disconnect the node_modules directory from meteor's installed node_modules directory. When meteor is updated, the app won't get the updates without manual intervention. This doesn't seem like a good long-term solution, perhaps it's the only solution? Is there nothing like a search path for modules so that meteor's modules could be on the search path and then all combined into one directory when meteor bundle was run? – Michael Grant Jan 28 '13 at 16:56
  • I would suggest making a Meteor package then that shims the node module you want to use. – DoctorPangloss Jan 28 '13 at 19:05