{"id":16326706,"url":"https://github.com/chrisyip/node_path_demo","last_synced_at":"2025-05-14T22:12:16.311Z","repository":{"id":30751273,"uuid":"34307765","full_name":"chrisyip/NODE_PATH_DEMO","owner":"chrisyip","description":null,"archived":false,"fork":false,"pushed_at":"2015-04-21T06:28:43.000Z","size":120,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-17T06:41:31.659Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chrisyip.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-21T06:05:21.000Z","updated_at":"2015-04-21T06:28:44.000Z","dependencies_parsed_at":"2022-09-11T05:10:17.291Z","dependency_job_id":null,"html_url":"https://github.com/chrisyip/NODE_PATH_DEMO","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisyip%2FNODE_PATH_DEMO","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisyip%2FNODE_PATH_DEMO/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisyip%2FNODE_PATH_DEMO/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisyip%2FNODE_PATH_DEMO/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chrisyip","download_url":"https://codeload.github.com/chrisyip/NODE_PATH_DEMO/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254235710,"owners_count":22036965,"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-10T23:09:21.389Z","updated_at":"2025-05-14T22:12:16.280Z","avatar_url":"https://github.com/chrisyip.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"This is a demo shows what node's `require` will act like if `$NODE_PATH` ends with a colon (':').\n\nTry this in a unix-like system\n\n```\ngit clone https://github.com/chrisyip/NODE_PATH_DEMO.git\ncd NODE_PATH_DEMO\nchmod +x run.sh\n./run.sh\n```\n\nYou'll see something like this:\n\n```\nUsing node v1.8.1\nCurrent NODE_PATH is '/usr/local/lib/node_modules'\nExecuting 'node foo/bar.js', you should seeing an error...\n\nIn foo/bar.js\nmodule.js:336\n    throw err;\n          ^\nError: Cannot find module 'index.js'\n    at Function.Module._resolveFilename (module.js:334:15)\n    at Function.Module._load (module.js:276:25)\n    at Module.require (module.js:363:17)\n    at require (module.js:382:17)\n    at Object.\u003canonymous\u003e (/Users/Chris/Workspace/node/NODE_PATH_DEMO/foo/bar.js:2:13)\n    at Module._compile (module.js:428:26)\n    at Object.Module._extensions..js (module.js:446:10)\n    at Module.load (module.js:353:32)\n    at Function.Module._load (module.js:308:12)\n    at Function.Module.runMain (module.js:469:10)\n\nAppeding a trailing colon to NODE_PATH\nNODE_PATH now is '/usr/local/lib/node_modules:' \u003c- notice the colon in the end\nExecuting 'node foo/bar.js'...\n\nIn foo/bar.js\nindex.js loaded\nindex.js: I should not be required\n```\n\nFunny, right? When requiring `index.js` in `foo/bar.js`, in normal situation, node will just throw an \"module not found\" exception.\n\nBut if `$NODE_PATH` ends with a colon, thing's going funny, node acts like search all the relative folders.\n\nDoes Anyone know why?\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisyip%2Fnode_path_demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchrisyip%2Fnode_path_demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisyip%2Fnode_path_demo/lists"}