ReferenceError "not defined"

ReferenceError "not defined"

本文关键字:quot defined not ReferenceError      更新时间:2024-06-02

不用说,我是一个初学者(当你看到我的问题时,你可能会明白的)。

我安装了节点代码是创建一个http服务器(如下)

> `var http = require('http'),
    host = '127.0.0.1',
    port = '9000' ;
var server = http.createServer(function(req, res){
  res.writeHead(200, {'Content-Type' :'text/html'}) ;
  res.end ('<h1> Hello World Joseph </h1>') ;
}) .listen(port, host, function() {
  console.log ('server Running on http://")' + host + ':' + port)
}) <
`

现在,我在一个名为hello.js的文件中有了这段代码我转到节点命令提示符,然后键入hello.js

我得到以下

ReferenceError: hello is not defined
    at repl:1:1
    at REPLServer.defaultEval (repl.js:262:27)
    at bound (domain.js:287:14)
    at REPLServer.runBound [as eval] (domain.js:300:12)
    at REPLServer.<anonymous> (repl.js:431:12)
    at emitOne (events.js:82:20)
    at REPLServer.emit (events.js:169:7)
    at REPLServer.Interface._onLine (readline.js:211:10)
    at REPLServer.Interface._line (readline.js:550:8)
    at REPLServer.Interface._ttyWrite (readline.js:827:14)

如有任何帮助,我们将不胜感激。

谢谢Joseph

我要回答的只是跟进我的评论:

我不确定你是否将<>或``放在代码中进行堆栈溢出格式化,也就是说这里是正确的代码,本质上这些东西需要删除:

var http = require('http'),
    host = '127.0.0.1',
    port = '9000' ;
var server = http.createServer(function(req, res){
  res.writeHead(200, {'Content-Type' :'text/html'}) ;
  res.end ('<h1> Hello World Joseph </h1>') ;
}) .listen(port, host, function() {
  console.log ('server Running on http://")' + host + ':' + port);
});

现在要在节点中运行该代码,只需转到包含该文件的目录,然后键入node hello.js