JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 145
  • Score
    100M100P100Q81529F

Simplifies requiring of modules by adding an intermediate namespace, where each namespace is associated with a directory.

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

During initialisation you create a namespace and associate it with a directory:

namespace.create('domain', __dirname + '/server/javascript/domain/', done)

At this point the directory is recursively scanned and a record of each file is kept. Anywhere that you want to require modules from the namespace you can do so simply:

var domain = require('namespace')('domain')
var TwitterConfigFactory = domain.require('TwitterConfigFactory')

In this last snippet of code we first get the domain namespace and then use it to require 'TwitterConfigFactory'. Its only when we ask for 'TwitterConfigFactory' that file with that same name is required.

Examples

Directory structure

domain
  authentication
    user.js
    twitter
      twitterAuthentication.js
namespace.create('domain', __dirname + '/server/javascript/domain/', done)
domain = require('namespace')('domain')
var twitterAuthentication = domain.require('twitterAuthentication') // NOTE - Doesn't matter that it was in a sub-directory
var twitterAuthentication = domain.require('user')