2016-07-28 119 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)

相关问题