0.2.2 • Published 6 years ago

requireg v0.2.2

Weekly downloads
222,005
License
-
Repository
github
Last release
6 years ago

requireg Build Status NPM version

Require and resolve 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.

It support both npm/yarn global packages installation paths.

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)
  • $NODE_MODULES (use the specific modules path environment variable)

Resolution priority

  1. Resolve via native require() (unless second parameter is true)
  2. User home directory ($HOME or %USERPROFILE%)
  3. Node installation path
  4. $NODE_MODULES (can have different multiple paths, semicolon separated)
  5. Common operative system installation paths

Installation

$ npm install requireg --save[-dev]
$ yarn add requireg

API

requireg(path: string, onlyGlobal: boolean = false)

Usage

Load global modules

var requireg = require('requireg')
// require a globally installed package
var npm = requireg('npm')

Load only global modules

var requireg = require('requireg')
// require a globally installed package and skip local packages
var eslint = requireg('eslint', true)

Resolve module path

var modulePath = requireg.resolve('npm')
// returns '/usr/local/lib/node_modules/npm/lib/npm.js'

Globalize it

require('requireg').globalize()

Now it is globally available from any source file

var globalModule = requireg('npm')

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 is 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 or yarn are supported (which means only standardized NPM paths are supported)

Possible extra features

  • Custom environment variable with custom path to resolve global modules.

License

Released under MIT license

@logigear/gondolajs@dlenroc/appium-playwright-driver@infinitebrahmanuniverse/nolb-requinightenv@everything-registry/sub-chunk-2655tastytargetstcb-bddweapp-gulp-servicexdltestframework@cristianps1988/ds-template@csssr/codeceptjs@compiiile/compiiile@compiiile/compiiile-projesh-calculationiotor-lmsql-cli-repltldrawligninutf-test-framework@asyncapi/generator@auto-canary/core@aviinash_jha/react-native-test_multiply@auto-it/core@ach/ach@abdullahceylan/expo-cli@abcnews/aunty@abcnews/generator-auntyykitykit-betaykit-cliykit-config-uglifyykit-prounibeautifyunibeautify-cliunsn-toolbox@firestead/cli@hakkajs/cli@edwinpb/scany@gaainf/codeceptjs@krenaldi/learnstorybook-design-system-template@labiebhn_/react-native-multiplier@kronoslive/codeceptjs@kronoslive/codeceptjs-utils-helper@labor-digital/lab-cli@logigear/gondola@leeonfield/ykit@nexrender/action-upload@nexrender/core@nexrender/server@expo/cli@expo/xdl@midlandsbank/node-nacha@merryjs/cli@jsoncv/core@pastash/filter_app_janus_tracer@pastash/pastash@skedulr/nebula-ui-library@restfulhead/auto-it-core@seekingmini/lrn-clinaropenframenyg-ui-generatorrofikingrofistarreact-native-adarsh_react_native_video_playerreact-native-avinash_jha_test_pluginregexp-requiresemantic-release-spec-mdreact-native-moosa-lib-for-testsemantic-release-confluencereact-native-test-multiplier-librarynmmes-clipgdeploypref-report-cliracoon-lmrecursive-copy-cliskira-guigrunt-wet-boew-fetchdistgrunt-narhuekinshuelog-slackhuetimerobothuetravishuetryhuestatusincanthermionahermione-chromedriverinspekterlite-devlsd-componentsmandocmarvin-climanan-react-native-expo-authorize-netlory-climedb@worldssportsgroup/bowerx@unibeautify/cli@svrx/create-plugin
0.2.2

6 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.8

7 years ago

0.1.7

8 years ago

0.1.6

9 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

12 years ago

0.1.2

12 years ago

0.1.1

12 years ago

0.1.0

12 years ago