If I write a script like containing console.log(__dirname); logs the value of __dirname. But if I try the same for the Node REPL like this happens:
> console.log(__dirname)
ReferenceError: __dirname is not defined
Thoughts?
If I write a script like containing console.log(__dirname); logs the value of __dirname. But if I try the same for the Node REPL like this happens:
> console.log(__dirname)
ReferenceError: __dirname is not defined
Thoughts?
Copyright © 2021 Jogjafile Inc.
From this What is the difference between __dirname and ./ in node.js? written by d512
The documentation says that
__dirnameis equal topath.dirname. If you typepath.dirnameinto the repel it tells you this:Now my guess is: Since it is a repl, you don't have a file which is stored somewhere on the disk. It simply reads the command, evaluates it and prints it to the console.
Someone with more experiences on REPLSs might give a longer and detailed answer, but I think this laid out the concept.