{"id":15591872,"url":"https://github.com/billiegoose/my_modules","last_synced_at":"2025-03-31T23:45:50.628Z","repository":{"id":57306416,"uuid":"53173691","full_name":"billiegoose/my_modules","owner":"billiegoose","description":"Keeps local modules out of node_modules, but still have working 'npm install' and 'require()'.","archived":false,"fork":false,"pushed_at":"2016-09-23T02:22:10.000Z","size":9,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-06T03:21:43.689Z","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":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/billiegoose.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":"2016-03-05T00:10:56.000Z","updated_at":"2017-02-28T21:31:12.000Z","dependencies_parsed_at":"2022-09-20T23:01:04.704Z","dependency_job_id":null,"html_url":"https://github.com/billiegoose/my_modules","commit_stats":null,"previous_names":["wmhilton/my_modules"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/billiegoose%2Fmy_modules","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/billiegoose%2Fmy_modules/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/billiegoose%2Fmy_modules/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/billiegoose%2Fmy_modules/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/billiegoose","download_url":"https://codeload.github.com/billiegoose/my_modules/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246558115,"owners_count":20796696,"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":"2024-10-02T23:49:49.382Z","updated_at":"2025-03-31T23:45:50.608Z","avatar_url":"https://github.com/billiegoose.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## DEPRECATED\n\n**I have ceased work on this project (and will hand over the project name if you ask nicely).**\n\n# Recommended Alternative\n\nIn the original motivation for this module, I put forth this scenario:\n\n\u003e Say your project layout looks something like:\n\u003e ```\n\u003e cool_project\n\u003e `-- app.js\n\u003e `-- package.json\n\u003e `-- lib\n\u003e |   `-- main.js\n\u003e |   `-- logger\n\u003e |   |   `-- logger.js\n\u003e |   |   `-- package.json\n\u003e |   `-- router\n\u003e |   |   `-- routes\n\u003e |   |   `-- router.js\n\u003e |   |   `-- package.json\n\u003e |   `-- api\n\u003e |       `-- index.js\n\u003e |       `-- package.json\n\u003e `-- node_modules\n\u003e ```\n\u003e\n\u003e You like having your project in modules (`logger`, `router`, and `api`) because it aids in unit testing and separation of concerns, but don't like publishing every module separately as its own git repository or on npmjs.org. But you end up with a workflow like:\n\u003e\n\u003e ```\n\u003e $ npm install\n\u003e $ cd lib/logger\n\u003e $ npm install\n\u003e $ cd ../router\n\u003e $ npm install\n\u003e $ cd ../api\n\u003e $ npm install\n\u003e ```\n\u003e\n\u003e and you start to go crazy. Maybe you try moving them to the `node_modules` folder, possibly in their own @scope, and then fight with git and npm only to have it still act wonky. Maybe you try `npm link` and all the options for local require() paths from [this article](https://gist.github.com/branneman/8048520) but nothing is perfect so nothing sticks.\n\nI have found a reasonable-ish solution to the craziness: *Put your package.json in the parent folder\nof your app code.* Put your custom modules in `cool_project/app/node_modules` and\ninstall your regular npm dependencies in `cool_project/node_modules` beside `app`.\nWhen node's `require` does not find the module in the current node_modules folder,\nit continues checking in each folder up to the root folder until it finds a module with the\nright name. (This is probably a bad design decision, because it makes modules indirectly\ndepend on every folder above them as well as below them, but that is not a useful discussion to have\nat this point. This is how `require()` works and we're stuck with it now.)\n\nRestructured project layout:\n\n```\ncool_project\n`-- package.json (all dependencies)\n`-- app\n|   `-- app.js\n|   `-- node_modules\n|       |`-- logger\n|       |   `-- logger.js\n|       |   `-- package.json (main, scripts, etc, but not dependencies)\n|       `-- router\n|       |   `-- routes\n|       |   `-- router.js\n|       |   `-- package.json (main, scripts, etc, but not dependencies)\n|       `-- api\n|           `-- index.js\n|           `-- package.json (main, scripts, etc, but not dependencies)\n`-- node_modules\n```\n\nBear with me and I'll walk you through how this works.\n\n#### Resolving npm modules from main code\nLet us say cool_project/app/app.js contains `require('express')`. Resolving will go like this:\n\n- Does cool_project/app/**node_modules** exist?\n  - Yes! Does cool_project/app/node_modules/**express** exist?\n    - No, go up one directory.\n  - Does cool_project/**node_modules** exist?\n    - Yes! Does cool_project/node_modules/**express** exist?\n      - Yes! Return module.\n\n#### Resolving custom modules from main code\nSuppose cool_project/app/app.js contains `require('logger')`.\n\n- Does cool_project/app/**node_modules** exist?\n  - Yes! Does cool_project/app/node_modules/**logger** exist?\n    - Yes! Return module.\n\n#### Resolving custom modules from custom modules\nLet's say that router.js runs `require('logger')`.\n\n- Does cool_project/app/node_modules/router/**node_modules** exist?\n  - No, go up one directory.\n- Does cool_project/app/node_modules/**node_modules** exist?\n  - No, go up one directory.\n- Does cool_project/app/**node_modules** exist?\n  - Yes! Does app/node_modules/**logger** exist?\n    - Yes! Return module.\n\n#### Resolving npm modules from custom modules.\nSay logger.js does a `require('chalk')`.\n\n- Does cool_project/app/node_modules/logger/**node_modules** exist?\n  - No, go up one directory.\n- Does cool_project/app/node_modules/**node_modules** exist?\n  - No, go up one directory.\n- Does cool_project/app/**node_modules** exist?\n  - Yes! Does app/node_modules/**chalk** exist?\n    - No, go up one directory.\n  - Does cool_project/**node_modules** exist?\n    - Yes! Does cool_project/node_modules/**chalk** exist?\n      - Yes! Return module.\n\n## Pros and Cons\n\nPros:\n\n- No extra hacking needed besides the directory structure.\n- Only one `npm install` command needed. No recursive installs.\n- Is not disrupted by npm3 node_modules flattening.\n\nCons:\n\n- Custom modules all live in one flat directory.\n- All module dependencies are saved together, which can lead to version coupling between custom modules.\n- Any \"dependencies\" listed in a custom module's package.json are a lie.\n- That directory is named `node_modules` so you probably have to explicitly un-ignore it in source control.\n\nThe cons are not that bad IMHO. If your modules were TRULY uncoupled, you'd be publishing them as such. This strategy\nis quick and works though, so you can gradually move code into modules for organization first, then work on\ntruly decoupling them (and giving them separate git repos and publishing them independently) later.\n\n## Status\n\nUnmaintained and deprecated. If you would like the \"my_modules\" package name I'm happy to hand it over.\n\n## Changelog\n\n2.0.1 - Deprecated\n\n2.0.0 - Bumped major version because my_modules will now force npm to install packages locally inside each package (my_modules/*/node_modules) instead of letting npm3 do its flattened top-level install. This was necessary to allow running multiple \"npm install\"s in parallel without race conditions. Switching to parallel execution cut the install time for my project from 22m to 8m so it was definitely worth it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbilliegoose%2Fmy_modules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbilliegoose%2Fmy_modules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbilliegoose%2Fmy_modules/lists"}