2

I'm a node.js begginer . Let's say I have an apache server(XAAMP) and node.js installed in C:\Program Files\nodejs\nodejs.exe on windows 7.

How can I run node.js in my apache server to simulate my code?

I mean, I know how to write node.js code but what I don't know how it's work on my server?

dot
  • 14,928
  • 41
  • 110
  • 218
  • Apache has nothing to do with it. You create the server in your node file and then start it up with `node path/to/your/file` – m59 Jul 24 '15 at 16:13
  • http://stackoverflow.com/questions/2353818/how-do-i-get-started-with-node-js – Reagan Gallant Jul 24 '15 at 16:14
  • @m59 ok but how to put it on public ? – mahmoud nezar sarhan Jul 24 '15 at 16:26
  • @mahmoudnezarsarhan You have to write the code. See a hello world server example. `http.createServer(function(req, res) { res.end('Hello world!'); }).listen(8080);` Then start it up: `node that-file.js`. And then visit `localhost:8080`. As simple as that. – m59 Jul 24 '15 at 16:30
  • 1
    @m59 I'm so sorry for this stupid questions but there are no one to ask but you ok say I made server like yours in the comment how people reach it ? – mahmoud nezar sarhan Jul 24 '15 at 16:36
  • people reach it by click to link http://yourserver:8080/ :) – vp_arth Jul 24 '15 at 17:34
  • maybe you want setup apache virtual host to proxy to your node.js app? – vp_arth Jul 24 '15 at 17:36
  • Great question.. No good answers so far. Let me re-phrase your question for you. `I want to use Node JS to handle serverside queries under Apache (and other IIS's) on Windows 7` - Is that even possible? Everywhere I look (inc below answers) says Use Node as a SERVER. That is probably the last thing I (or anyone?) would ever want to do on this planet. I have never heard of a Node being the front end entry point on a www server or a serious IIS. Does it even do encryption? What's the point? An intranet experiment? As a test environment?(not much of a test if it can't be replicated real world). – www-0av-Com Mar 03 '18 at 20:16

3 Answers3

1

Apache server don't need for Node.js.

For create your own Node.js server:

  1. Download and install Node.js

  2. Create file 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:

    node hello.js
    
  4. Open your browser and point it at http://localhost:3000/. This should display a web page that says:

    Hello world
    

A basic HTTP server

Node.js Manual & Documentation

shilovk
  • 11,718
  • 17
  • 75
  • 74
0

If you like to work with a replacement for XAAMP you should finally take a look at MEAN.io.

At NpmJS.org you will find different solutions for most of your needs.

and like Reagan Gallant commented you should take a look at this famous stackoverflow post (if you need ideas).

NodeSchool indeed is a good entry point for your fist steps. After that npmjs will make sense and finally you will love Mean.io

Community
  • 1
  • 1
Danny
  • 1,078
  • 7
  • 22
0

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.

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

Soren
  • 14,402
  • 4
  • 41
  • 67