简体   繁体   English

如何在装有Apache服务器的Windows上运行node.js?

[英]how to run node.js on windows with apache server installed in?

I'm a node.js begginer . 我是一个node.js初学者。 Let's say I have an apache server(XAAMP) and node.js installed in C:\\Program Files\\nodejs\\nodejs.exe on windows 7. 假设我在Windows 7的C:\\Program Files\\nodejs\\nodejs.exe安装了一个apache服务器(XAAMP)和C:\\Program Files\\nodejs\\nodejs.exe

How can I run node.js in my apache server to simulate my code? 如何在apache服务器中运行node.js来模拟代码?

I mean, I know how to write node.js code but what I don't know how it's work on my server? 我的意思是,我知道如何编写node.js代码,但是我不知道它如何在服务器上工作?

Apache server don't need for Node.js. Apache服务器不需要Node.js。

For create your own Node.js server: 要创建自己的Node.js服务器:

  1. Download and install Node.js 下载并安装Node.js

  2. Create file hello.js : 创建文件hello.js

     var http = require("http"); var server = http.createServer().listen(3000); // beter way for create server.on("request", function(req, res){ res.writeHead(200, {"Content-Type": "text/plain"}); // for view at page http://localhost:3000 res.write("Hello world"); res.end(); }); server.on("listening", function(){ // for view in console console.log("Listen: 3000..."); }); 
  3. In terminal go to dir where file hello.js and type: 在终端中转到文件hello.js目录并键入:

     node hello.js 
  4. Open your browser and point it at http://localhost:3000/ . 打开浏览器并将其指向http:// localhost:3000 / This should display a web page that says: 这应该显示一个网页,其中包含:

     Hello world 

A basic HTTP server 基本的HTTP服务器

Node.js Manual & Documentation Node.js手册和文档

If you like to work with a replacement for XAAMP you should finally take a look at MEAN.io . 如果您想使用XAAMP的替代产品,那么最后应该看看MEAN.io。

At NpmJS.org you will find different solutions for most of your needs. NpmJS.org上,您可以找到满足大多数需求的不同解决方案。

and like Reagan Gallant commented you should take a look at this famous stackoverflow post (if you need ideas). 就像里根·加兰特(Reagan Gallant)评论的那样,您应该看一下这个著名的stackoverflow帖子(如果您需要想法)。

NodeSchool indeed is a good entry point for your fist steps. 实际上,NodeSchool是您迈出第一步的一个很好的切入点。 After that npmjs will make sense and finally you will love Mean.io 之后,npmjs将变得有意义,最后您将爱上Mean.io

You just make it use a different port than Apache is using (for example port 3000 which is the default for express-js and others) -- that is assuming that you don't need the two to work together. 您只需使其使用与Apache使用的端口不同的端口即可(例如,端口3000(这是express-js和其他端口的默认端口))–假设您不需要两者一起工作。

If you do need them to work together, you add a forwarding module to Apache and configure the forwarding in Apache of certain URL to go to your local port for node-js 如果确实需要它们一起工作,则可以向Apache添加转发模块,并在Apache中配置某些URL的转发,以转到node-js的本地端口

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

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