# requireg

> Require and resolve global modules like a boss

Latest version **0.2.2** (published 2019-05-24) · 0 weekly downloads

## Install

```sh
npm install requireg
pnpm add requireg
yarn add requireg
bun add requireg
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2019-05-24 |
| First published | 2013-12-09 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 4.0.0 |
| Dependencies | 3 |
| Unpacked size | 52.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 44 |
| Maintainers | h2non |
| Keywords | global, npm, modules, module, require, import, resolve |

## Links

- npm: https://www.npmjs.com/package/requireg
- Repository: https://github.com/h2non/requireg
- Homepage: http://github.com/h2non/requireg
- Issues: https://github.com/h2non/requireg/issues
- npm.io page: https://npm.io/package/requireg

## Dependencies (3)

- [rc](https://npm.io/package/rc.md) ~1.2.7
- [resolve](https://npm.io/package/resolve.md) ~1.7.1
- [nested-error-stacks](https://npm.io/package/nested-error-stacks.md) ~2.0.1

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 0.2.2 (latest) — 2019-05-24
- 0.2.1 — 2018-08-22
- 0.2.0 — 2018-08-20
- 0.1.8 — 2018-06-02
- 0.1.7 — 2017-07-26
- 0.1.6 — 2016-09-17
- 0.1.5 — 2015-03-29
- 0.1.4 — 2015-03-28
- 0.1.3 — 2013-12-15
- 0.1.2 — 2013-12-12
- 0.1.1 — 2013-12-09
- 0.1.0 — 2013-12-09

## README

# requireg  [![Build Status](https://secure.travis-ci.org/h2non/requireg.png?branch=master)][2] [![NPM version](https://badge.fury.io/js/requireg.png)][3]

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][1]. 

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

```bash
$ npm install requireg --save[-dev]
```

```bash
$ yarn add requireg
```

## API

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

## Usage

### Load global modules

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

### Load only global modules

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

### Resolve module path

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

### Globalize it

```js
require('requireg').globalize()
```

Now it is globally available from any source file

```js
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](https://npmjs.org) or [yarn](https://yarnpkg.com) 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

[1]: http://nodejs.org/docs/latest/api/modules.html#modules_all_together
[2]: http://travis-ci.org/h2non/requireg
[3]: http://badge.fury.io/js/requireg

---
_Source: https://npm.io/package/requireg · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
