文本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