Skip to content
TomTasche edited this page Jan 30, 2012 · 6 revisions

Modules

anode contains basic support for modules, whereby modules of different flavours can be installed and uninstalled via an intent API.

Limitations

Note that the functionality provided, at present, is not comparable to npm. Module packages are not processed by npm, and therefore install-time scripts are not run, and any binaries included in a module are not processed. Furthermore, there is no version awareness or dependency awareness. In short, the functionality provided does not amount to a package manager, but is simply a convenience to be able to simply add and remove module packages in various formats, and allow them to be installed into anode's private filesystem area without root privileges.

A port of npm is being investigated, and will hopefully appear in a forthcoming version of anode. However, even when this does happen, there will inevitably be limitations in functionality - local module repositories would be unlikely to be supported, for example.

Module types

anode currently supports the following module types:

  • pure JS, presented in a package or as a single standalone script with a .js extension;

  • native addons with a .node extension.

anode supports installation via a few different package formats:

  • a directory containing a tree of files (eg on the storage card);

  • zip archives with a .zip extension;

  • compressed tar archives with a .tar.gz or .tgz extension.

Module organisation

anode installs packages into the /data/data/org.meshpoint.anode/node_modules/ directory. Inside this directory, each module is installed either as a standalone file with appropriate extension (if presented as a standalone addon or js file) or as a directory, with the module contents unpacked beneath that directory. This matches the layout expected by node itself.

On a rooted device it is possible to copy files and directories into this location to manage this space by hand; however, on a non-rooted phone this isn't possible so it is necessary to use anode's API.

Module API

An intent-based API is provided, with two actions:

  • org.meshpoint.anode.INSTALL with extras path (mandatory, path to the module resource or package) and module (optional, module name to use to install). If the module name is not specified, it is guessed from the path. The path specifier may be a fully qualified path to a file or directory, or may be an http or https URI. If it is a URI, anode will download a standalone module file (JS or addon) or a module package from that location. Direct download of a directory tree from a remote location is not supported; use a supported package type instead.

  • org.meshpoint.anode.UNINSTALL with extra module argument to specify the module to be removed. The module argument must be the module identifier, and not the filename - eg hello instead of hello.js or hello.node.

So, to install the addon that is in the file /data/tmp/hello.node, use the command:

adb shell am broadcast -a org.meshpoint.anode.INSTALL -e path /data/tmp/hello.node

To install the packaged module that is online at http://mymodules.com/hello.tgz use the command:

adb shell am broadcast -a org.meshpoint.anode.INSTALL -e path http://mymodules.com/hello.tgz

To uninstall either of these modules, use the command:

adb shell am broadcast -a org.meshpoint.anode.UNINSTALL -e module hello
Clone this wiki locally