[英]Install Node.js
I'm completely new to node.js. 我对node.js完全陌生。 By reading the documentation and tutorials, I managed to download and install node.js on my windows. 通过阅读文档和教程,我设法在Windows上下载并安装了node.js。
How do I test it and make it work? 如何测试并使其正常工作?
The file test.js is saved in the same directory as node.exe and contains: 文件test.js与node.exe保存在同一目录中,并且包含:
console.log('Hello World');
Openning the command-line I typed: 打开我输入的命令行:
$ node test.js
But nothing hapenns, just: 但是什么都没有发生,只是:
...
You are typing node test.js
in the Node REPL not the command line. 您在Node REPL而不是命令行中输入node test.js
。 The ...
is indicating that you haven't reached the end of a valid statement yet (because you are writing shell and not JavaScript). ...
表示您尚未到达有效语句的末尾(因为您正在编写shell而不是JavaScript)。
Run a command line with your terminal emulator of choice (probably Windows Powershell if you are using Windows). 使用所选的终端仿真器运行命令行(如果使用Windows,则可能是Windows Powershell)。
Run the Node REPL by executing node via the command-line without any arguments. 通过不带任何参数的命令行执行节点来运行节点REPL。 The reason you're not getting the expected results is probably because you're running node.exe
directly. 无法获得预期结果的原因可能是因为您正在直接运行node.exe
。 Since you're using windows, start up CMD
and run node.exe
from there. 由于您使用的是Windows,因此请启动CMD
并从那里运行node.exe
。 Once you have the REPL running, try node test.js
again, and this time it will work. 一旦运行了REPL, node test.js
再次尝试node test.js
,这一次它将起作用。
![enter image description here][1]I have run it in nodejs shell and it is simply working ![在此处输入图片描述] [1]我已经在nodejs shell中运行了它,并且很简单
> console.log('Hello World');
Hello World
undefined
>
Also I opened nodejs command prompt not default command prompt of windows and then 我也打开了Windows的nodejs命令提示符而不是默认命令提示符,然后
node path_to_file
it is working... same output 它正在工作...相同的输出
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.