Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

esm-module-paths

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esm-module-paths

Returns dirname and filename for ESM modules in node

  • 1.1.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
2.5K
increased by37.82%
Maintainers
1
Weekly downloads
 
Created
Source

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 and expressions each time to achieve the same.

This package makes this a bit easier.

Usage

Imagine a file in ./your/path/index.js

import { getModulePaths } from "esm-module-paths";

const { __dirname, __filename } = getModulePaths();

console.log(__dirname); // /your/path
console.log(__filename); // /your/path/index.js

For convenience reasons, the library also exports __filename and __dirname as functions, which can be used independently.

import { __filename, __dirname } from "esm-module-paths";

console.log(__dirname()); // /your/path
console.log(__filename()); // /your/path/index.js

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 } from "esm-module-paths";

console.log(getDirName()); // /your/path
console.log(getFileName()); // /your/path/index.js

Installation

npm install esm-module-paths

or

yarn add esm-module-paths

FAQs

Package last updated on 21 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc