Why is __dirname not defined in node REPL?

后端 未结 11 1458
傲寒
傲寒 2020-12-12 14:23

From the node manual I see that I can get the directory of a file with __dirname, but from the REPL this seems to be undefined. Is this a misunderstanding on my

11条回答
  •  执笔经年
    2020-12-12 15:18

    Seems like you could also do this:

    __dirname=fs.realpathSync('.');
    

    of course, dont forget fs=require('fs')

    (it's not really global in node scripts exactly, its just defined on the module level)

提交回复
热议问题