I am try loading a simple js file on the node.js console and it never shows me the result. I have a test.js file with a single line: console.log("testing");
If I enter directly the command into the console it works but by doing node test.js it shows me ... loading.
2131 次
1 回答
4
node test.js当您已经在REPL(您所说的 node.js 控制台)中时,您正尝试调用该命令。REPL 只接受 JavaScript。
因此,REPL 中的命令node test.js是一个 JavaScript 语法错误,但是 REPL 尝试通过缓冲命令并提示您输入更多输入(即...)来从语法错误中恢复。请参阅REPL 代码中的此处。
你可以
- 退出 REPL 并从您的终端/控制台提供测试文件作为节点可执行文件的参数,即
node test.js(我认为您打算这样做)
或者正如@JonathanLonowski 建议的那样,您可以在 REPL 中使用:
(在测试文件所在目录启动节点REPL时)
于 2013-10-29T16:31:31.153 回答