All Projects → h2non → requireg

h2non / requireg

Licence: MIT License
Resolve and require local & global modules in node.js like a boss

Programming Languages

javascript
184084 projects - #8 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to requireg

lint-deps
Lint for unused or missing dependencies in your node.js projects. Customize with plugins or configuration.
Stars: ✭ 48 (+6.67%)
Mutual labels:  modules, require, import
Shrimpit
Shrimpit 🍤 is a small CLI analysis tool for checking unused JavaScript, JSX & Vue templates ES6 exports in your project.
Stars: ✭ 255 (+466.67%)
Mutual labels:  modules, import
get-installed-path
Get locally or globally installation path of given package name.
Stars: ✭ 39 (-13.33%)
Mutual labels:  modules, path
global-prefix
Get the npm global path prefix. Same code used internally by npm.
Stars: ✭ 27 (-40%)
Mutual labels:  path, global
tradeship
Automatically imports missing JavaScript dependencies and removes unused ones.
Stars: ✭ 42 (-6.67%)
Mutual labels:  require, import
konan
find all require/import calls by walking the AST
Stars: ✭ 48 (+6.67%)
Mutual labels:  require, import
file-icon-cli
Get the icon of a file or app as a PNG image (macOS)
Stars: ✭ 73 (+62.22%)
Mutual labels:  path
keyring-social-importers
A collection of importers which pull your content back from social networks, and into your own WordPress install.
Stars: ✭ 26 (-42.22%)
Mutual labels:  import
decentraland-dapps
🛠 Common modules for dApps
Stars: ✭ 96 (+113.33%)
Mutual labels:  modules
nuxt-humans-txt
🧑🏻👩🏻 "We are people, not machines" - An initiative to know the creators of a website. Contains the information about humans to the web building - A Nuxt Module to statically integrate and generate a humans.txt author file - Based on the HumansTxt Project.
Stars: ✭ 27 (-40%)
Mutual labels:  modules
relative
Easily calculate the relative path from file A to file B in Node.js project. Will calculate correctly from a file to a directory, file to file, directory to file, and directory to directory.
Stars: ✭ 34 (-24.44%)
Mutual labels:  path
monopati
Well-typed paths
Stars: ✭ 20 (-55.56%)
Mutual labels:  path
relax
Relax is a set of tools for modeling, documenting and testing RESTFul APIs
Stars: ✭ 12 (-73.33%)
Mutual labels:  modules
svg-path-bbox
SVG paths bounding box calculator
Stars: ✭ 17 (-62.22%)
Mutual labels:  path
modules
🧩 Java modules published at Maven Central
Stars: ✭ 115 (+155.56%)
Mutual labels:  modules
relative-path
Portable relative UTF-8 paths for Rust.
Stars: ✭ 54 (+20%)
Mutual labels:  path
pkg-require
require node files relative to your package directory
Stars: ✭ 22 (-51.11%)
Mutual labels:  require
anzip
Simple async unzip library for Node.js
Stars: ✭ 61 (+35.56%)
Mutual labels:  import
plugins
Elder.js plugins and community plugins.
Stars: ✭ 80 (+77.78%)
Mutual labels:  path
l2cu
L²CU: LDraw Linux Command line Utility
Stars: ✭ 14 (-68.89%)
Mutual labels:  import

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 supports 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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].