esm-module-paths
ESM modules don't allow to use __dirname
and __filename
do determine a .js
file's location.
Instead, you need to copy/paste multiple lines each time to achieve the same.
This package makes this a bit easier.
Usage
Imagine a file in ./your/path/index.js
import { __dirname, __filename } from "esm-module-paths";
console.log(__dirname());
console.log(__filename());
Since __dirname
and __filename
being functions may be confusing to some, especially since those used to be variables, this package also exports aliased, more descriptive versions of each function.
import {getFileName, getDirName}
Installation
npm install esm-module-paths
or
yarn add esm-module-paths