从节点手册我看到,我可以得到__dirname
文件的目录,但从REPL这似乎是未定义的。这是我的误解还是错误?节点__dirname没有定义
$ node
> console.log(__dirname)
ReferenceError: __dirname is not defined
at repl:1:14
at REPLServer.eval (repl.js:80:21)
at Interface.<anonymous> (repl.js:182:12)
at Interface.emit (events.js:67:17)
at Interface._onLine (readline.js:162:10)
at Interface._line (readline.js:426:8)
at Interface._ttyWrite (readline.js:603:14)
at ReadStream.<anonymous> (readline.js:82:12)
at ReadStream.emit (events.js:88:20)
at ReadStream._emitKey (tty.js:320:10)
你也不能使用一些内幕RequireJS模块的全局变量。如果您在服务器端使用RequireJS,请参阅http://stackoverflow.com/questions/9027429/how-to-use-nodejs-global-module-objects-in-requirejs-modules。 – Eye 2012-11-05 08:25:04
是的,这应该真的被添加到答案眼睛,因为这是什么让我。 – 2015-10-12 17:14:01
不将它添加到REPL的加载脚本是令人讨厌的。我想不出任何原因,它不会在那里...... – jcollum 2015-11-18 21:16:14