Javascript 第一次使用 node.js - “ReferenceError: node is not defined”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27170037/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
First time using node.js - "ReferenceError: node is not defined"
提问by Rick Sanchez
I just installed node.js. I tried writing node -v that should check the version - and it's not working. this is the output:
我刚刚安装了 node.js。我尝试编写 node -v 来检查版本 - 但它不起作用。这是输出:
> node -v ReferenceError: node is not defined
at repl:1:2 at REPLServer.self.eval (repl.js:110:21)
at Interface.<anonymous> (repl.js:239:12)
at Interface.emit (events.js:95:17)
at Interface._onLine (readline.js:202:10)
at Interface._line (readline.js:531:8)
at Interface._ttyWrite (readline.js:760:14)
at ReadStream.onkeypress (readline.js:99:10)
at ReadStream.emit (events.js:98:17)
at emitKey (readline.js:1095:12) >
I opened it using git - command: node
我使用 git - 命令打开它: node
I tried running it using "Git", thought maybe that's the issue and I get the exact same output.
我尝试使用“Git”运行它,认为这可能是问题所在,我得到了完全相同的输出。
I am using windows 8 if it's relevant - followed this tutorial till now:
如果相关,我正在使用 Windows 8 - 遵循本教程直到现在:
https://www.youtube.com/watch?v=tlntE8fe6u4
https://www.youtube.com/watch?v=tlntE8fe6u4
How do I make it work?
我如何使它工作?
回答by benbrunton
It looks like you have entered the node REPLand then typed node -v
看起来你已经进入节点REPL然后输入node -v
The good news is that this means node is working!
好消息是这意味着节点正在工作!
To check the version from here you can type process.versionto get the node version. Alternatively type process.exit()to exit the node REPL and get back to bash (or equivalent terminal).
要从此处检查版本,您可以键入process.version以获取节点版本。或者键入process.exit()退出节点 REPL 并返回到 bash(或等效终端)。
From here node -vshould just output the node version.
从这里node -v应该只输出节点版本。
回答by Irf
Edit
编辑
First time using node.js
第一次使用 node.js
Although already answered, but just putting in my 2-cents,
虽然已经回答了,但只是投入我的 2 美分,
Normally, the first time users would trip over it, so am posting some screen shots, and that OP wants to try node -v, so making it a bit easierto follow.
通常,第一次用户会被它绊倒,所以我发布了一些屏幕截图,并且 OP 想要尝试node -v,所以让它更容易理解。
The Wrong !!
错的 !!
The Correct !!
正确的 !!
or you can do ..
或者你可以做..
Hope it helps someone.!
希望它可以帮助某人。!
回答by Bernard Doci
Instead of node.exe, try to run node from "Node.js command prompt".
尝试从“ Node.js 命令提示符”运行 node,而不是 node.exe 。
First, you should install nodejs.msi from nodejs.org.
首先,您应该从nodejs.org安装nodejs.msi。
Once installation is completed, go to: Start> All Programs> Node.js> Node.js command prompt.
安装完成后,转到:开始>所有程序> Node.js> Node.js 命令提示符。
It worked for me.
它对我有用。
回答by AMOL
Even I faced the same when I install the NODE server and Try to execute "node-v" command from directly clicking on start up menu's NODE ICON. Instead of doing that all you need to do is GO TO command prompt then go to C:/program files/node path and type "node -v" command it will definitely going to display you the version of NODE.
即使我在安装 NODE 服务器并尝试通过直接单击启动菜单的 NODE ICON 执行“node-v”命令时也面临同样的问题。而不是这样做,您需要做的只是转到命令提示符,然后转到 C:/program files/node 路径并键入“node -v”命令,它肯定会向您显示 NODE 的版本。
回答by Rakesh Verma
Follow below Steps:
请按照以下步骤操作:
- Open command prompt: RUN > CMD
- Navigate to folder where nodejs is installed: C:\users\name>cd path_of_nodejs
- Open nodejs: C:\path_of_nodejs>node
- Exit from node REPL mode: >process.exit()
- You are ready for your node commands: >node -v
- 打开命令提示符:RUN > CMD
- 导航到安装 nodejs 的文件夹:C:\users\name>cd path_of_nodejs
- 打开nodejs:C:\path_of_nodejs>node
- 退出节点 REPL 模式:>process.exit()
- 您已准备好执行节点命令:>node -v
回答by Jay Kareliya
Try opening up a new terminal (Run -> CMD) and then executing:
尝试打开一个新终端(运行 -> CMD)然后执行:
node /your_file_name.js
And to see which version you have installed, just execute:
要查看您安装了哪个版本,只需执行:
node -v
回答by trevor
Thanks for this help.
感谢您的帮助。
If you are using windows, like me, and want a desktop shortcut and you already have the nice node.js desktop icon, edit the shortcut properties like this:
如果您像我一样使用 Windows,并且想要一个桌面快捷方式并且您已经拥有漂亮的 node.js 桌面图标,请像这样编辑快捷方式属性:
- right click and select properties
- click change Icon, select the current icon and click OK (to lock it in)
- in the target box, change it all to simply say cmd or c:\windows\System32\cmd.exe if you are pedantic.
- 右键单击并选择属性
- 单击更改图标,选择当前图标并单击确定(将其锁定)
- 在目标框中,将其全部更改为简单地说 cmd 或 c:\windows\System32\cmd.exe 如果您是迂腐的。
now you have a command prompt, with the node.js icon, that opens in the folder you expect, that responds correctly to the node -v command.
现在你有一个命令提示符,带有 node.js 图标,它在你期望的文件夹中打开,正确响应 node -v 命令。


