文本server.js中有如下代码:
var http=require('http');
http.createServer(function(request,response){
response.writeHead(200,{'Content-Type':'text/plain'});
response.end("HelloWorld");
}).listen(8888);
console.log("server is running");
打开命令窗口,执行 node server.js 抛出SyntaxError : unexpected identifier
因为不确定错误的位置,将console.log移到第二行,仍然报错,怀疑是没有找到http
cmd执行npm install http -g 重新安装http后无错误
访问 http://localhost:8888 返回 HelloWorld