How to Run Node JS Behind Apache

Node is an API for writing scalable network services in JavaScript. Because of its fast-changing nature, the Node documentation may be sparse or out of date, making it difficult to learn certain tasks. For instance, the documentation's quick how-tos only show you how to run Node, not how to connect it to the Apache Web server.

Instructions

    • 1

      Open a text editor and create a new JavaScript file.

    • 2

      Put the following text into the file:

      var http = require('http');
      http.createServer(function (request, response) {
      response.writeHead(200, {'Content-Type': 'text/html'});
      response.end('<html><head></head><body><h1>Hello World</h1></body></html>\n');
      }).listen(8080, "127.0.0.1");
      console.log('Server running at http://127.0.0.1:8080/');

    • 3

      Drag and drop the file onto the node.exe program. This tells Node JS to execute your JavaScript file.

    • 4

      Add the following line to the end of your Apache configuration file, which is is located at "C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf" by default:

      ProxyPass / http://localhost:1337/

    • 5

      Open a Web browser and navigate to your Apache server at "http://localhost/." You will see "Hello World" served by your Node JS behind your Apache server.

Related Searches:

References

Resources

Comments

Related Ads

Featured