Why __dirname is undefined | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why __dirname is undefined

Hi, I am working on a nodejs website and I have added ("type": "module") in the package.json file so I can use the ES6 (from ... import ... ) syntax but when I try to console.log (__dirname) it tells me that it is *undefined* so why is that??

16th May 2021, 9:45 PM
Ouboukioud Aissa
Ouboukioud Aissa - avatar
2 Answers
16th May 2021, 11:53 PM
Calviղ
Calviղ - avatar
+ 3
From definition -A variable that has not been assigned a value is of type undefined . -A method or statement also returns undefined if the variable that is being evaluated does not have an assigned value. - A function returns undefined if a value was not returned .
16th May 2021, 11:10 PM
Apongpoh Gilbert
Apongpoh Gilbert - avatar