{"id":15551595,"url":"https://github.com/bahmutov/node-hook","last_synced_at":"2025-09-28T23:31:19.389Z","repository":{"id":13149242,"uuid":"15831764","full_name":"bahmutov/node-hook","owner":"bahmutov","description":"Run source transform function on node require call","archived":false,"fork":false,"pushed_at":"2017-07-24T16:29:45.000Z","size":22,"stargazers_count":66,"open_issues_count":4,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-27T20:43:35.968Z","etag":null,"topics":["hook","nodejs","require"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bahmutov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-01-11T22:20:10.000Z","updated_at":"2023-09-08T16:44:42.000Z","dependencies_parsed_at":"2022-08-29T22:51:02.274Z","dependency_job_id":null,"html_url":"https://github.com/bahmutov/node-hook","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fnode-hook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fnode-hook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fnode-hook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fnode-hook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bahmutov","download_url":"https://codeload.github.com/bahmutov/node-hook/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234570361,"owners_count":18854155,"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":["hook","nodejs","require"],"created_at":"2024-10-02T14:05:39.802Z","updated_at":"2025-09-28T23:31:19.045Z","avatar_url":"https://github.com/bahmutov.png","language":"JavaScript","readme":"# node-hook\n\n\u003e Run source transform function on Node require\n\n[![NPM][node-hook-icon]][node-hook-url]\n\n[![Build status][node-hook-ci-image]][node-hook-ci-url]\n[![dependencies][node-hook-dependencies-image]][node-hook-dependencies-url]\n[![devdependencies][node-hook-devdependencies-image]][node-hook-devdependencies-url]\n[![semantic-release][semantic-image] ][semantic-url]\n\n## Install and use\n\n```sh\nnpm install --save node-hook\n```\n\nBefore loading desired *.js* files, install hook\n\n```js\nvar hook = require('node-hook');\n\nfunction logLoadedFilename(source, filename) {\n    return 'console.log(\"' + filename + '\");\\n' + source;\n}\nhook.hook('.js', logLoadedFilename);\nrequire('./dummy');\n// prints fulle dummy.js filename, runs dummy.js\n\nhook.unhook('.js'); // removes your own transform\n```\n\n**remember:** Nodejs caches compiled modules, so if the transform is not\nworking, you might need to delete the cached entry in `require.cache`,\nthen call `require(filename)` again to force reload.\n\nRelated: Node require replacement [really-need](https://github.com/bahmutov/really-need).\n\nYou can hook several transformers thanks to the [code](https://github.com/bahmutov/node-hook/pull/2)\nsubmitted by [djulien](https://github.com/djulien)\n\n## Existing transform\n\nYou can get the current transform and run any source through it. For example\nto see how the current source looks when loaded but before evaluated\n\n```js\nconst filename = resolve('./call-foo.js')\nconst transform = Module._extensions['.js']\nconst fakeModule = {\n  _compile: source =\u003e {\n    console.log('transformed code')\n    console.log(source)\n  }\n}\ntransform(fakeModule, filename)\n```\n\n## Small print\n\nAuthor: Gleb Bahmutov \u0026copy; 2013\n\n* [Changelog](History.md)\n* [@bahmutov](https://twitter.com/bahmutov)\n* [glebbahmutov.com](http://glebbahmutov.com)\n* [blog](http://glebbahmutov.com/blog/)\n\nLicense: [MIT](MIT-license.md) - do anything with the code,\nbut don't blame me if it does not work.\n\nSupport: if you find any problems with this module, email / tweet / open issue on Github\n\n[node-hook-icon]: https://nodei.co/npm/node-hook.svg?downloads=true\n[node-hook-url]: https://npmjs.org/package/node-hook\n[node-hook-ci-image]: https://travis-ci.org/bahmutov/node-hook.svg?branch=master\n[node-hook-ci-url]: https://travis-ci.org/bahmutov/node-hook\n[node-hook-dependencies-image]: https://david-dm.org/bahmutov/node-hook.svg\n[node-hook-dependencies-url]: https://david-dm.org/bahmutov/node-hook\n[node-hook-devdependencies-image]: https://david-dm.org/bahmutov/node-hook/dev-status.svg\n[node-hook-devdependencies-url]: https://david-dm.org/bahmutov/node-hook#info=devDependencies\n[semantic-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg\n[semantic-url]: https://github.com/semantic-release/semantic-release\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahmutov%2Fnode-hook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbahmutov%2Fnode-hook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahmutov%2Fnode-hook/lists"}