Skip to content

src: command line option to preload modules

Rodrigo Muino Tomonari requested to merge github/fork/ofrobots/vendor-startup into v1.x

Here's a proposal, along with a PR, I would like to get feedback from the community on.

It would be nice if there was a standard mechanism to allow vendors, such as a cloud host, to customize startup of node applications.

Basically, I want to be able to inject functionality into a node application without requiring an explicit require. This could be useful to automatically enable, e.g., vendor specific tracing and application performance monitoring APIs when applications are deployed.

There are a few ways this could be done: 0. (Status quo) Ask the developers to modify their applications and add an explicit require of a vendor provided npm module. This adds friction to the deployment experience and possibly prevents people from being able to easily try different cloud vendors.

  1. The vendor can maintain their own fork of node.js/io.js but with extra functionality added. This package would be offered instead of the standard node.js/io.js packages. This is potentially high overhead for the vendor. Effort may be duplicated by different vendors.
  2. Build a standard mechanism into node.js/io.js that allows vendors to inject some functionality into the node startup process.

Here's a proposal on how to do option 2 (EDIT: updated as per suggestions by @piscisaureus):

  • On startup, node checks if process.env.NODE_VENDOR_STARTUP is set. If so, the file node_prefix + '/lib/vendor/index.js' is loaded (if it exists).
  • Vendors could package up their distributions of node/io by adding lib/vendor. Another alternative would be for NODE_VENDOR_STARTUP to be a path. It gives more flexibility, but is probably not as secure.

EDIT: 20150313: change to command line option.

iojs -r foo -r /bar/baz.js -r quux

translates to:

require('foo');
require('/bar/baz.js');
require('quux');

Thoughts?

Merge request reports

Loading