deno current directory 1

deno current directory

const currentDir = decodeURI(new URL('.', import.meta.url).pathname).replace('/', '');

Here is what the above code is Doing:
1. We’re using the `import.meta` object to get the URL of the current file.
2. We’re using the `URL` constructor to create a new URL object from the current file’s URL.
3. We’re using the `pathname` property of the URL object to get the path of the current file.
4. We’re using the `decodeURI` function to decode the path of the current file.
5. We’re using the `replace` method to remove the leading slash from the path.
6. We’re assigning the path to the `currentDir` variable.

Now that we have the path of the current directory, we can use it to create a new `Directory` object.

Similar Posts