node.js 节点未定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14196257/
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
node is not defined
提问by MuriloKunze
I just create a js file with the following code(exactly the code from official page):
我只是使用以下代码创建了一个 js 文件(正是来自官方页面的代码):
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
So, I install node from the 'Install' button in the official page too(for windows). But when I try to run the program it gives me the following:
因此,我也从官方页面中的“安装”按钮安装节点(对于 Windows)。但是当我尝试运行该程序时,它给了我以下信息:


but the strange thing is this:
但奇怪的是:


回答by Marcos Placona
You need to run that from your terminal (cmd) as opposed to Node's repl.
您需要从终端 (cmd) 运行它,而不是 Node 的 repl。
Try opening up a new terminal (Run -> CMD) and then executing:
尝试打开一个新终端(Run -> CMD)然后执行:
node /your_file_name.js
节点 /your_file_name.js
To see which version you have installed, just execute:
要查看您安装了哪个版本,只需执行:
node -v
节点 -v
回答by Sollymanul Islam
There are two things needed to do.. First you need to add an environment variable. like path=C:\Program Files\nodejs for me. Second.. you have to open the command prompt then redirect the prompt to the location where you have kept your file.. like if you have kept your file on c:/practice and your file name is server.js then you have to redirect the command prompt to that location.
有两件事需要做..首先你需要添加一个环境变量。像 path=C:\Program Files\nodejs 对我来说。其次..你必须打开命令提示符然后将提示重定向到你保存文件的位置..就像你把文件保存在 c:/practice 并且你的文件名是 server.js 那么你必须重定向命令提示符到该位置。
And then run the command node server.js and everything will work properly..
然后运行命令 node server.js 一切都会正常工作..
回答by Mike B.
There are few approaches:
有几种方法:
- Inside of console of Windows (aka
CMD):
- Windows 控制台内部(又名
CMD):
node -v
节点 -v
- Inside of console of Node.js (aka
Node.js REPLterminal):
- Node.js 的控制台内部(又名
Node.js REPL终端):
process.version
进程版本
- The more detailed information (versions number of all sub-modules) can be retrieved by (inside of
Node.js REPL):
- 更详细的信息(所有子模块的版本号)可以通过(内部
Node.js REPL)检索:
process.versions
进程.versions
回答by Plynx
You're at the console. You probably want to run node server.jsfrom the Windows Command Prompt (cmd.exe).
你在控制台。您可能希望node server.js从 Windows 命令提示符 ( cmd.exe) 运行。
回答by nickleefly
did you add nodedirectory to your PATH.
您是否将node目录添加到您的 PATH。
If you install the latest one, the installer would add it for you
如果您安装最新的,安装程序会为您添加它

