This module enables you to load global modules in Node.js.
First install the module:
npm install require-g --save
import requireG from 'require-g';
const MyGlobalModule = requireG('my-global-module');
MyGlobalModule.run();
You can override the require hook by using register module and use global:...
prefix.
import 'require-g/register';
import MyGlobalModule from 'global:my-global-module';
// or require('global:my-global-module');
MyGlobalModule.run();
You can get all global module names:
import requireG from 'require-g';
const globalModules = requireG.modules;
console.log(globalModules);
/*
will return ['mocha', 'gulp', ...]
*/