2016-07-28 54 views
1

我試過的步驟: 1.(確定)從官方網站安裝節點:https://nodejs.org/en/download/ 結果:我可以打開cmd(在任何位置,輸入節點然後使用命令象「的console.log」和它打印我的消息)如何安裝node.js並在Eclipse中創建項目

2(失敗)安裝使用快遞npm install -g express從CMD給我一個錯誤(圖片附enter image description here

3.(OK)我」使用以下命令成功安裝express:npm install express(不含-g) 4.(確定)編寫一個簡單的Hello World程序。 :

var http = require('http'); 

// Configure our HTTP server to respond with Hello World to all requests. 
var server = http.createServer(function (request, response) { 
    response.writeHead(200, {"Content-Type": "text/plain"}); 
    response.end("Hello World\n"); 
}); 

// Listen on port 8000, IP defaults to 127.0.0.1 
server.listen(8000); 

// Put a friendly message on the terminal 
console.log("Server running at http://127.0.0.1:8000/"); 

5.(失敗),但我想運行一個更大的項目中,除了一個js文件,我也有一個index.html文件。如果我將這兩個文件都移動到節點安裝目錄,則一切正常。但我想能夠將我的項目保存在其他地方。如果我嘗試使用node C:\Users\marius\Downloads\chat-example-master\indes.js運行,則會收到錯誤:Cannot find module express。因此,似乎當我安裝沒有「-g」的express時,我只能在節點目錄中工作(如果您有任何疑問,請告知我)。 6.(失敗)當從Eclipse創建一個Node.js項目時,我選擇空項目,沒有模板,然後添加一個簡單的js文件(帶有Hello World的文件),右鍵單擊項目名稱 - > run as - >運行配置 - >節點應用程序 - >新建 - >添加我的.js文件 - >運行。我收到以下錯誤:出現執行命令行 異常(從http://techprd.com/how-to-setup-node-js-project-in-eclipse/步驟)

Cannot run program "node" (in directory "C:\Users\marius\workspace\FirstNodeProject"): CreateProcess error=2, The system cannot find the file specified 

要回顧一下:我想是能夠在cmd並創建運行位於具有「節點」隨處節點項目node.js和表達項目並從Eclipse運行它們。 如果您需要更多信息,請讓我知道。

回答

0

只是爲了讓別人知道他們是否遇到過這個問題。我可以從任何地方運行快速應用程序,但是在每個應用程序的根文件夾中,我必須使用npm install express。 在Eclipse中,你需要做的是:Window-> Preferences-> Nodeclipse->取消選中「在PATH上找到.Node」並插入到Node.js路徑中輸入你的node.exe位置(在我的情況下:C:\ Program Files \ nodejs \ node.exe)