Node.js TypeError:http.createServer不是函数
我正在尝试在AWS上安装Node,安装后,我正在使用http.createServer,这给了我以下错误Node.js TypeError:http.createServer不是函数,node.js,amazon-ec2,Node.js,Amazon Ec2,我正在尝试在AWS上安装Node,安装后,我正在使用http.createServer,这给了我以下错误 http.createServer(function (req, res) { ^ TypeError: http.createServer is not a function at Object.<anonymous> (/home/ubuntu/test1/test1.js:4:6) at Module._compile (module.js:65
http.createServer(function (req, res) {
^
TypeError: http.createServer is not a function
at Object.<anonymous> (/home/ubuntu/test1/test1.js:4:6)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3
我测试了你的代码,对我来说效果很好。您使用的是哪个节点版本?您安装了http模块吗?@RémiC
http
是nodejsnode-v8.11中的默认值。1@AnkitAgarwal你说得对,我的错。我有相同的节点版本,所以它不是…我通过我的IDE启动它,你如何启动它?如果我使用命令行,我会得到一个端口异常,所以我将它改为8080,它工作正常,你能试试吗?
var http = require('http');
var port = 9000;
http.createServer(function(req, res){
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello there, world\n');
}).listen(port);
console.log("Listening on port " + port);