Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mcollina/desm
get the file directory from import.meta.url
https://github.com/mcollina/desm
Last synced: 4 days ago
JSON representation
get the file directory from import.meta.url
- Host: GitHub
- URL: https://github.com/mcollina/desm
- Owner: mcollina
- License: mit
- Created: 2020-06-03T20:40:05.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-01-29T14:48:18.000Z (12 months ago)
- Last Synced: 2024-12-28T12:10:44.579Z (11 days ago)
- Language: JavaScript
- Size: 14.6 KB
- Stars: 115
- Watchers: 4
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# desm
The missing one-liner utility to get the dirname from `import.meta.url`.
Requires Node 12.17.0 or Node 14.0.0.
Starting in [Node 20.11.0](https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V20.md#20.11.0) and [Node 21.2.0](https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V21.md#21.2.0) this is now built in: [`import.meta.dirname`](https://nodejs.org/api/esm.html#importmetadirname) / [`import.meta.filename`](https://nodejs.org/api/esm.html#importmetafilename)
## Install
```
npm i desm
```## Usage
```js
import desm from 'desm'console.log(desm(import.meta.url))
```or
```js
import { dirname, filename, join } from 'desm'// same as CommonJS __dirname
console.log(dirname(import.meta.url))// same as CommonJS __filename
console.log(filename(import.meta.url))// same as CommonJS path.join(__dirname, 'routes')
console.log(join(import.meta.url, 'routes'))// same as CommonJS path.join(__dirname, '..', 'other')
console.log(join(import.meta.url, '..', 'other'))
```## License
MIT