Dirname and filename

The Node.js constants __dirname and __filename are not available when running a JavaScript file as an ES Module.

If you need to use these constants, the url library provides a fileURLToPath function which allows you to compute their values from import.meta.url.

Was this page helpful?