Package Exports
- requireg
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 (requireg) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
requireg 
Require global modules in node.js like a boss
Differences with require()
requireg
tries to find modules in global locations which are
not natively supported by the node.js module resolve algorithm.
Supported locations:
- $HOME/node_modules (instead of $HOME/.node_modules)
- $HOME/node_libraries (instead of $HOME/.node_libraries)
- $HOME/node_packages (specific of
requireg
) - $PREFIX/lib/node_modules (instead of $PREFIX/lib/node)
Resolution priority
- Resolve via native
require()
- User home directory (
$HOME
or%USERPROFILE%
) - Node installation path
- Common operative system installation paths
Installation
$ npm install requireg --save[-dev]
Usage
var requireg = require('requireg')
// require a globally installed package
var coffee = requireg('coffee-script')
Globalize it
require('requireg').globalize()
Now it is globally available from any source file
var globalModule = requireg('coffee-script')
Module not found
requireg
maintains the same behavior as the native require()
.
It will throw an Error
exception if the module was not found
Considerations
- Require global modules in node.js are considered anti-pattern.
Note that you can experiment unreliability or inconsistency across different environments.
I hope you know exactly what you do with
requireg
- Only node packages installed with NPM are supported (which means only standardized NPM paths are supported)
Wish list
- Custom environment variable with custom path to resolve global modules
- Possible configuration object (force to use only global modules...)