Why is __dirname not defined in node REPL?

__dirname is only defined in scripts. It’s not available in REPL.

try make a script a.js

console.log(__dirname);

and run it:

node a.js

you will see __dirname printed.

Added background explanation: __dirname means ‘The directory of this script’. In REPL, you don’t have a script. Hence, __dirname would not have any real meaning.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)