{"id":15439643,"url":"https://github.com/h2non/requireg","last_synced_at":"2025-04-06T22:08:54.905Z","repository":{"id":12245611,"uuid":"14859402","full_name":"h2non/requireg","owner":"h2non","description":"Resolve and require local \u0026 global modules in node.js like a boss","archived":false,"fork":false,"pushed_at":"2022-03-01T02:16:25.000Z","size":41,"stargazers_count":45,"open_issues_count":4,"forks_count":14,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-01T22:17:36.702Z","etag":null,"topics":["global","import","modules","node","path","require","resolve"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/h2non.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-12-02T10:27:35.000Z","updated_at":"2023-03-17T14:35:18.000Z","dependencies_parsed_at":"2022-09-06T09:50:35.299Z","dependency_job_id":null,"html_url":"https://github.com/h2non/requireg","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2non%2Frequireg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2non%2Frequireg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2non%2Frequireg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2non%2Frequireg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/h2non","download_url":"https://codeload.github.com/h2non/requireg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247557767,"owners_count":20958047,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["global","import","modules","node","path","require","resolve"],"created_at":"2024-10-01T19:08:20.135Z","updated_at":"2025-04-06T22:08:54.882Z","avatar_url":"https://github.com/h2non.png","language":"JavaScript","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]\n\nRequire and resolve global modules in node.js like a boss.\n\n## Differences with require()\n\n`requireg` tries to find modules in global locations which are\nnot natively supported by the node.js [module resolve algorithm][1]. \n\nIt supports both npm/yarn global packages installation paths.\n\nSupported locations:\n\n- $HOME/node_modules (instead of $HOME/.node_modules)\n- $HOME/node_libraries (instead of $HOME/.node_libraries)\n- $HOME/node_packages (specific of `requireg`)\n- $PREFIX/lib/node_modules (instead of $PREFIX/lib/node)\n- $NODE_MODULES (use the specific modules path environment variable)\n\n## Resolution priority\n\n1. Resolve via native `require()` (unless second parameter is true)\n2. User home directory (`$HOME` or `%USERPROFILE%`)\n3. Node installation path\n4. $NODE_MODULES (can have different multiple paths, semicolon separated)\n5. Common operative system installation paths\n\n## Installation\n\n```bash\n$ npm install requireg --save[-dev]\n```\n\n```bash\n$ yarn add requireg\n```\n\n## API\n\n### requireg(path: string, onlyGlobal: boolean = false)\n\n## Usage\n\n### Load global modules\n\n```js\nvar requireg = require('requireg')\n// require a globally installed package\nvar npm = requireg('npm')\n```\n\n### Load only global modules\n\n```js\nvar requireg = require('requireg')\n// require a globally installed package and skip local packages\nvar eslint = requireg('eslint', true)\n```\n\n### Resolve module path\n\n```js\nvar modulePath = requireg.resolve('npm')\n// returns '/usr/local/lib/node_modules/npm/lib/npm.js'\n```\n\n### Globalize it\n\n```js\nrequire('requireg').globalize()\n```\n\nNow it is globally available from any source file\n\n```js\nvar globalModule = requireg('npm')\n```\n\n### Module not found\n\n`requireg` maintains the same behavior as the native `require()`.\nIt will throw an `Error` exception if the module was not found\n\n## Considerations\n\n- Require global modules in node.js is considered anti-pattern.\nNote that you can experiment unreliability or inconsistency across different environments.\nI hope you know exactly what you do with `requireg`\n- Only node packages installed with [npm](https://npmjs.org) or [yarn](https://yarnpkg.com) are supported (which means only standardized NPM paths are supported)\n\n## Possible extra features\n\n- Custom environment variable with custom path to resolve global modules.\n\n## License\n\nReleased under MIT license\n\n[1]: http://nodejs.org/docs/latest/api/modules.html#modules_all_together\n[2]: http://travis-ci.org/h2non/requireg\n[3]: http://badge.fury.io/js/requireg\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh2non%2Frequireg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fh2non%2Frequireg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh2non%2Frequireg/lists"}