Why is __dirname not defined in node REPL?

后端 未结 11 1485
傲寒
傲寒 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:16

    In ES6 use:

    import path from 'path';
    const __dirname = path.resolve();
    

    also available when node is called with --experimental-modules

提交回复
热议问题