Skip to content

Instantly share code, notes, and snippets.

@cadorn
Created November 24, 2009 20:06
Show Gist options
  • Save cadorn/242158 to your computer and use it in GitHub Desktop.
Save cadorn/242158 to your computer and use it in GitHub Desktop.

From System Module

require('<module>')  // search require.paths
require('./<module>')  // resolve relative then search require.paths
require('<module>', '<package>') // module from package

or

require('system#<module>')  // search require.paths
require('./<module>')  // resolve relative then search package (system package == require.paths)
require('<package>#<module>') // module from package

From Using Module

require('<module>')  // search require.paths
require('./<module>')  // resolve relative then search package
require('<module>', '<package>') // module from package

or

require('system#<module>')  // search require.paths
require('./<module>')  // resolve relative then search package
require('<package>#<module>') // module from package

Notes

  • Whenever <package> is specified the module loads within a package context limiting relative searches to the package. The owning package of a module can be identified by module["package"]
  • On startup the package context is undefined defaulting to system module behaviour. No module["package"] defined
  • Relative paths ../../../../ may not point outside of require.paths nor package
  • If <package> does not match an alias for a package descriptor in package.json it is matched against <sea>/using/<package>/package.json in which case <package> is called a top-level ID

Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment