我正在尝试在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: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
以下是我在test1.js中输入的代码
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);