Replies: 5 comments 3 replies
-
Which version of Node.js? https://nodejs.org/dist/latest-v17.x/docs/api/modules.html#__dirname |
Beta Was this translation helpful? Give feedback.
-
v14.16.0 |
Beta Was this translation helpful? Give feedback.
-
Yes, I do get the error. Module object does not have the property __dirname. I have not yet reported this issue to Node.js projects. I receive the following error. |
Beta Was this translation helpful? Give feedback.
-
Thanks for your clarification. It works fine when it is called from a file, but it remains inaccessible from console. Now, I have understood that the __dirname binds to the file where it is called from. Hence, it returns directory name only when they are called from file, otherwise it throws the reference error. But, process.cwd() and path.resolve() returns the current working directory where the console is pointing at. |
Beta Was this translation helpful? Give feedback.
-
Yes, you are right. Initially, I misunderstood that both are same. Thank you very much for your timely answer that helped me correct my mistake. |
Beta Was this translation helpful? Give feedback.
-
The newer versions of Node.js does not support "__dirname". It would be better if it can be replaced with "process.cwd()" or "path.resolve()".
This need to be made in the following file.
"/docs/guide.md"
Beta Was this translation helpful? Give feedback.
All reactions