Skip to main content
Adding additional context.
Source Link
Luillyfe
  • 6.8k
  • 8
  • 38
  • 48

I am not sure why this answerStarting from Nodejs v20, there is not listed above but anywaya better way:

const __dirname = import.meta.dirname;

https://nodejs.org/api/esm.html#differences-between-es-modules-and-commonjs

I am not sure why this answer is not listed above but anyway:

const __dirname = import.meta.dirname;

https://nodejs.org/api/esm.html#differences-between-es-modules-and-commonjs

Starting from Nodejs v20, there is a better way:

const __dirname = import.meta.dirname;

https://nodejs.org/api/esm.html#differences-between-es-modules-and-commonjs

Source Link
Luillyfe
  • 6.8k
  • 8
  • 38
  • 48

I am not sure why this answer is not listed above but anyway:

const __dirname = import.meta.dirname;

https://nodejs.org/api/esm.html#differences-between-es-modules-and-commonjs