{"id":13808192,"url":"https://github.com/rhysd/dirname-filename-esm","last_synced_at":"2025-06-14T21:39:21.767Z","repository":{"id":57212313,"uuid":"223425660","full_name":"rhysd/dirname-filename-esm","owner":"rhysd","description":"__dirname and __filename for ES Modules environment","archived":false,"fork":false,"pushed_at":"2024-07-11T11:14:04.000Z","size":31,"stargazers_count":69,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-30T18:04:49.176Z","etag":null,"topics":["commonjs","compatibility","es-modules","node"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/dirname-filename-esm","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/rhysd.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-22T14:56:01.000Z","updated_at":"2025-04-28T01:44:48.000Z","dependencies_parsed_at":"2024-08-04T01:09:07.899Z","dependency_job_id":"c84c240f-3dcc-4c64-bbef-18a0df21646c","html_url":"https://github.com/rhysd/dirname-filename-esm","commit_stats":{"total_commits":29,"total_committers":4,"mean_commits":7.25,"dds":"0.13793103448275867","last_synced_commit":"3c17db1789eeaa93abc62c591fda00ffba7fd53d"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Fdirname-filename-esm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Fdirname-filename-esm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Fdirname-filename-esm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Fdirname-filename-esm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rhysd","download_url":"https://codeload.github.com/rhysd/dirname-filename-esm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Fdirname-filename-esm/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":258213806,"owners_count":22665806,"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":["commonjs","compatibility","es-modules","node"],"created_at":"2024-08-04T01:01:37.069Z","updated_at":"2025-06-14T21:39:21.749Z","avatar_url":"https://github.com/rhysd.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"`__dirname` and `__filename` for ES Modules on Node.js\n======================================================\n[![CI][ci-badge]][ci]\n[![npm][npm-ver]][npm]\n\nNode.js v13.2.0 was released with support for ES Modules. [The official announcement][announce] explains\nthe overview.\n\nIn ES Modules environment, global variables such as `require`, `exports`, `module.exports`, `__filename`,\n`__dirname` are not available. `require`, `exports`, `module.exports` are no longer necessary in favor\nof ESM, but we still need `__filename` and `__dirname` which can be calculated from `import.meta.url`.\n\nTo make the migration from commonjs to ES Modules smooth, [dirname-filename-esm][npm] provides functions\nto create `__dirname` and `__filename` variables easily in an ES Modules environment.\n\n## Installation\n\n```sh\nnpm install --save dirname-filename-esm\n```\n\n## Usage\n\nUsage is very straightforward.\n\n```javascript\n// In \".mjs\" script or a script under \"type\": \"module\" package\nimport { dirname, filename } from 'dirname-filename-esm';\n\nconst __dirname = dirname(import.meta);\nconst __filename = filename(import.meta);\n\n// Use __dirname and __filename like in a commonjs module\n```\n\nTwo functions are exported.\n\n- `dirname()` takes `import.meta` object and returns `__dirname` value of the script.\n- `filename()` takes `import.meta` object and returns `__filename` value of the script.\n\nThese functions return an empty string if `import.meta` doesn't have `url` property.\n\nThis package has zero dependency.\n\nThis package offers [TypeScript](https://www.typescriptlang.org/) support. Since this package is for\nES Modules environment, ensure that `module` option is set to one of the following values in your `tsconfig.json`.\n\n- `es2020` or later\n- `node16` or later\n\n## License\n\n[the MIT License](./LICENSE.txt)\n\n\n[ci]: https://github.com/rhysd/dirname-filename-esm/actions/workflows/ci.yml\n[ci-badge]: https://github.com/rhysd/dirname-filename-esm/actions/workflows/ci.yml/badge.svg\n[npm]: https://www.npmjs.com/package/dirname-filename-esm\n[npm-ver]: https://badge.fury.io/js/dirname-filename-esm.svg\n[announce]: https://medium.com/@nodejs/announcing-core-node-js-support-for-ecmascript-modules-c5d6dc29b663\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhysd%2Fdirname-filename-esm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frhysd%2Fdirname-filename-esm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhysd%2Fdirname-filename-esm/lists"}