Node.js modules best practice (draft)

intro

Loading a module in Node.js is done with

var mymod = require("somepathtomymod");

The path of the module refers to :

The path itself can be in Node.js search path (NODE_PATH, see Node.js documentation), or an absolute or relative filesystem path.

Because of the plurality of ways to load a module, it is inevitable there is a plurality of ways to (debian-)package and install a module.

This page tries to explain the best and most compatible way to install a module.

how to install a module

A module typically has already a source tree layout with directories like "lib", "bin", and a package.json file at its root.

Installing is as simple as:

This usually allows source to be kept unpatched (except for the nodejs rename):

declare a build-dependency on nodejs

The nodejs package depends on libv8 and doesn't build on some architectures. Because of that, node-* packages having "Architecture: all" are available on architectures where nodejs isn't available - and so are uninstallable on those architectures. To work around that inconvenience to the users, simply declare an unversioned "Build-Depends: nodejs".

Declaring that build-dependency is also quite natural in the case of a package running its test suite during its build.