{"id":24821357,"url":"https://github.com/nodejs/require-in-the-middle","last_synced_at":"2025-05-14T14:08:19.435Z","repository":{"id":45657619,"uuid":"51443433","full_name":"nodejs/require-in-the-middle","owner":"nodejs","description":"Module to hook into the Node.js require function","archived":false,"fork":false,"pushed_at":"2025-02-21T18:37:55.000Z","size":150,"stargazers_count":174,"open_issues_count":15,"forks_count":30,"subscribers_count":17,"default_branch":"main","last_synced_at":"2025-05-04T23:36:57.613Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/nodejs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":"GOVERNANCE.md","roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-02-10T13:42:55.000Z","updated_at":"2025-02-21T18:37:34.000Z","dependencies_parsed_at":"2024-01-13T21:40:46.256Z","dependency_job_id":"42b6c43e-a024-419b-ae9e-47b3690c52a6","html_url":"https://github.com/nodejs/require-in-the-middle","commit_stats":{"total_commits":113,"total_committers":8,"mean_commits":14.125,"dds":0.2920353982300885,"last_synced_commit":"89db35035423ff14e814b7e9a43ce7bcc82b1d24"},"previous_names":["nodejs/require-in-the-middle","elastic/require-in-the-middle"],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodejs%2Frequire-in-the-middle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodejs%2Frequire-in-the-middle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodejs%2Frequire-in-the-middle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodejs%2Frequire-in-the-middle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nodejs","download_url":"https://codeload.github.com/nodejs/require-in-the-middle/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253309428,"owners_count":21887986,"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":[],"created_at":"2025-01-30T18:02:08.011Z","updated_at":"2025-05-14T14:08:19.392Z","avatar_url":"https://github.com/nodejs.png","language":"JavaScript","readme":"# require-in-the-middle\n\nHook into the Node.js `require` function. This allows you to modify\nmodules on-the-fly as they are being required.\n\n[![npm](https://img.shields.io/npm/v/require-in-the-middle.svg)](https://www.npmjs.com/package/require-in-the-middle)\n[![Test status](https://github.com/nodejs/require-in-the-middle/workflows/Test/badge.svg)](https://github.com/nodejs/require-in-the-middle/actions)\n\nAlso supports hooking into calls to `process.getBuiltinModule()`, which was introduced in Node.js v22.3.0.\n\n## Installation\n\n```\nnpm install require-in-the-middle --save\n```\n\n## Usage\n\n```js\nconst path = require('path')\nconst { Hook } = require('require-in-the-middle')\n\n// Hook into the express and mongodb module\nnew Hook(['express', 'mongodb'], function (exports, name, basedir) {\n  const version = require(path.join(basedir, 'package.json')).version\n\n  console.log('loading %s@%s', name, version)\n\n  // expose the module version as a property on its exports object\n  exports._version = version\n\n  // whatever you return will be returned by `require`\n  return exports\n})\n```\n\n## API\n\nThe require-in-the-middle module exposes a single function:\n\n### `hook = new Hook([modules][, options], onrequire)`\n\nWhen called a `hook` object is returned.\n\nArguments:\n\n- `modules` \u0026lt;string[]\u003e An optional array of module names to limit which modules\n  trigger a call of the `onrequire` callback. If specified, this must be the\n  first argument. Both regular modules (e.g. `react-dom`) and\n  sub-modules (e.g. `react-dom/server`) can be specified in the array.\n- `options` \u0026lt;Object\u003e An optional object containing fields that change when the\n  `onrequire` callback is called. If specified, this must be the second\n  argument.\n  - `options.internals` \u0026lt;boolean\u003e Specifies whether `onrequire` should be called\n    when module-internal files are loaded; defaults to `false`.\n- `onrequire` \u0026lt;Function\u003e The function to call when a module is required.\n\nThe `onrequire` callback will be called the first time a module is\nrequired. The function is called with three arguments:\n\n- `exports` \u0026lt;Object\u003e The value of the `module.exports` property that would\n  normally be exposed by the required module.\n- `name` \u0026lt;string\u003e The name of the module being required. If `options.internals`\n  was set to `true`, the path of module-internal files that are loaded\n  (relative to `basedir`) will be appended to the module name, separated by\n  `path.sep`.\n- `basedir` \u0026lt;string\u003e The directory where the module is located, or `undefined`\n  for core modules.\n\nReturn the value you want the module to expose (normally the `exports`\nargument).\n\n### `hook.unhook()`\n\nRemoves the `onrequire` callback so that it will not be triggerd by\nsubsequent calls to `require()` or `process.getBuiltinModule()`.\n\n## License\n\n[MIT](https://github.com/nodejs/require-in-the-middle/blob/master/LICENSE)\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodejs%2Frequire-in-the-middle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnodejs%2Frequire-in-the-middle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodejs%2Frequire-in-the-middle/lists"}