繁体   English   中英

如何在Eclipse中安装node.js并创建项目

[英]How to install node.js and create project in Eclipse

我尝试过的步骤:1。(确定)从官方网站安装节点: https//nodejs.org/en/download/结果:我可以打开cmd(在任何位置,键入节点然后使用命令,如“console.log”并打印我的消息)

2.(失败)使用npm install -g express从cmd npm install -g express给我一个错误(附图片 在此输入图像描述

3.(好)我使用以下命令成功安装express npm install express (不带-g)4.(OK)编写一个简单的Hello World程序。 Javascript文件:

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运行node C:\\Users\\marius\\Downloads\\chat-example-master\\indes.js我收到错误: Cannot find module express 因此,当我在没有“-g”的情况下安装express时,我只能在节点目录中使用它。(如果您有任何疑问,请告诉我)。 6.(失败)当从Eclipse创建Node.js项目时,我选择空项目,没有模板,然后添加一个简单的js文件(带有Hello World的文件),右键单击项目名称 - >运行为 - >运行配置 - >节点应用程序 - >新建 - >添加我的.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”的任何位置的节点项目,并创建node.js并表达项目并从Eclipse运行它们。 如果您需要更多信息,请与我们联系。

只是为了让其他人知道他们是否遇到过这个问题。 我可以从任何地方运行快速应用程序,但在每个应用程序的根文件夹中我必须npm install express 在Eclipse中,您只需要:Window-> Preferences-> Nodeclipse->取消选中“在PATH上查找.Node”并插入Node.js路径输入您的node.exe位置(在我的情况下:C:\\ Program Files \\的NodeJS \\ node.exe)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM