Sent on Dec 6, 2023

Getting dirname in Node with ES Modules

If you haven’t switch over to ES Modules when using Node, you probably should — that’s because ESM is supported almost everywhere now and many useful libraries already support ESM.

One of the problems with turning on ESM support in Node, is that we lose the ability to get the path to the directory easily.

Previously, we can use __dirname to get it.

But no longer.

How to get dirname in ESM

Today, I’m going to show you how to get __dirname and how to make the process easier.

Here’s a link to today’s article.

I hope you enjoy it.

As usual, let me know if this is helpful — and if you want me to cover anything else.

Stay awesome,
Zell