How to manage requireJS based packages for Node.js applications

Since coming across RequireJS I have started to adopt it wholeheartedly as it seems a great way of organising dependencies etc.

For my current project I have created a 'package' of requireJS-organised modules, which will provide the needed database API, to many node.js applications.

But I have come across a stumbling block ... how can I allow third party applications to use my package, without needing to faff with requireJS?

My directory structure for my applications and API is currently as follows:

api_package/node_modules
api_package/controllers/*
api_package/views/*
api_package/helpers/*
api_package/models/*
api_package/main.js

application_1/node_modules
application_1/app.js

application_2/node_modules
application_2/app.js

I need my applications to be self-contained - so they can be easily deployed - so my current work around is to copy api_package/* into the 'node_modules' directory of application_1 & 2 and setting the their requirejs config to the following:

(function() {
  var requirejs;

  requirejs = require('requirejs').config({
    baseUrl: __dirname,
    nodeRequire: require,
    packages: [
      {
        name: 'api_package',
        location: './node_modules/api_package'
      }
    ]
  });

This feels a little dirty and wrong!

Is there a better way? Am I missing some packaging feature for requireJS?

Is it even possible to hide the implementation details of my api_package (the detail being that I am using requireJS) and allow applications to use it as they would any other module:

require('api_package')

You can use the amdefine package, which allows you to code to the AMD API and have the module work in node programs without requiring those other programs to use AMD.

In addition to the documentation on the amdefine github page, this is also documented on the RequireJS website.