Package Exports
- require-namespace
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (require-namespace) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Node.js Namespaces
When you require modules in node.js you include the path to the file which means that moving files break dependent modules.
To avoid that issue the new notion of a namespace allows you to require a dependency in a way that is more loosely coupled to the directory structure on disk.
Installation
$ npm install require-namespaceUsage
During initialisation you synchronously create a namespace and associate it with a directory:
global.domain = namespace.createSync('domain', __dirname + '/domain/')At this point the directory is recursively scanned and a record of each file is kept. Since we saved the namespace to a global variable we can then require files from it like this:
var LinkContentProcessor = domain.require('LinkContentProcessor')That require will work if there was a file called 'LinkContentProcessor' anywhere within the directory we used when creating the namespace.
If we don't want to use a global variable for the namespace then requiring becomes a bit more wordy:
var domain = require('require-namespace')('domain')
var LinkContentProcessor = domain.require('LinkContentProcessor')Example
The project comes with an example that you can run using
node examples/simple.jsTests
The tests use vows and can be run using:
vows spec/*_spec.jsWhat next
- More tests
- More examples