我试图在一个名为hello.js的单独文件中运行用javascript编写的hello world程序
目前正在运行node.js的windows版本.
代码在控制台窗口中运行完美,但如何在Windows环境中引用该路径.
C:\abc\zyx\hello.js
Run Code Online (Sandbox Code Playgroud)
在Unix中我猜它显示$ node hello.js
我是Node.js的新手.如果我做错了,请纠正我.
我试过了
> node C:\abc\zyx\hello.js ----没用
> C:\abc\zyx\hello.js - 不行
UPDATE1:
将node.exe添加到hello.js文件所在的文件夹中.
添加了文件夹c:\ abc\zyx \的路径点,我收到一条错误消息
ReferenceError:未定义hello
看到hello.js的内容
setTimeout(function() {
console.log('World!');
}, 2000);
console.log('Hello');
Run Code Online (Sandbox Code Playgroud)
更新2:
到目前为止,我已经尝试了所有这些版本,但它们似乎都没有用.可能是我做错了.
>node hello.js
>$ node hello.js
>node.exe hello.js
>node /hello.js
>node \hello.js
> \node \hello.js
> /node /hello.js
> C:\abc\xyz\node.exe C:\abc\xyz\hello.js
> C:\abc\xyz\node.exe C:/abc/xyz/hello.js
> hello.js
> /hello.js
> \hello.js
>node hello
Run Code Online (Sandbox Code Playgroud)
请参阅我的文件结构

已解决:请 尝试使用以下选项在命令提示符下运行,而不是运行node.exe.
c:\>node c:\abc\hello.js
Hello
World! (after 2 secs)
Run Code Online (Sandbox Code Playgroud)