2016-04-11 56 views
2

我運行first.js獲取Microsoft JScript中的編譯錯誤

var http = require("http"); 

http.createServer(function (request, response) { 

    // Send the HTTP header 
    // HTTP Status: 200 : OK 
    // Content Type: text/plain 
    response.writeHead(200, {'Content-Type': 'text/plain'}); 

    // Send the response body as "Hello World" 
    response.end('Hello World\n'); 
}).listen(8124); 

// Console will print the message 
console.log('Server running at http://127.0.0.1:8124/'); 

的一段代碼,而I M與gitbash它給人的願望輸出運行它。但使用節點js命令提示它給微軟jscript編譯錯誤。

+0

的node.js無關使用JScript,所以你使用的是錯誤的解釋運行腳本。 – user3173842

回答

0

這裏的問題可能來自幾個地方。最可能的安裝爲基礎。

下面的代碼(從上方觀察)

var http = require("http"); 
http.createServer(function (request, response) { 
response.writeHead(200, {'Content-Type': 'text/plain'}); 
response.end('Hello World\n'); }).listen(8124); 
console.log('Server running at http://127.0.0.1:8124/'); 

產生正結果時,我試圖加載在瀏覽器中。 因此,我提出以下建議:

  1. 儘量跑什麼,我投入的代碼片段窗口進入一個全新的first.js文件中的一個全新的目錄,然後在命令行導航到該目錄並運行該文件命令「Node first.js」(自然不用引號)。

1.1如果使用任何編輯器除了純文本編輯器(記事本++,記事本,昇華等)保證該文件是在-實際上設置爲輸出純文本(骨頭移動但常常被忽視)

  • 重新安裝節點(值得一試)

  • 如果一切都失敗了,你已經安裝了故宮,鍵入「故宮安裝HTTP」,然後重新運行你的應用程序first.js

  • 1

    看起來您剛剛在終端窗口中鍵入了腳本名稱,因此要求Windows爲您的腳本找到正確的解釋器。你應該試着和解釋的NodeJS的腳本:

    node your-script.js 
    

    不僅僅是

    your-script.js 
    
    相關問題