Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

requireg

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

requireg

Require and resolve global modules like a boss

  • 0.1.8
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
471K
decreased by-40.9%
Maintainers
1
Weekly downloads
 
Created
Source

requireg Build Status NPM version

Require and resolve global modules in node/io.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)
  • $NODE_MODULES (use the specific modules path environment variable)

Resolution priority

  1. Resolve via native require()
  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]

Usage

Load global modules

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

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 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...)

License

Released under MIT license

Keywords

FAQs

Package last updated on 02 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc