Question

I have an apache web server running on my ubuntu server box. Recently, I was attempting to learn JavaScript and I stumbled upon node.js. I'd like to create a few web application multiplayer games and I've learnt that node.js could come in handy. I was experiencing a few issues with the configuration. How would I go about running both apache server and node.js on the same machine? I don't mind it if the applications on node.js are on a different port and have to be accessed by typing in websitename:portNumber. I am not too concerned about the performance advantages/disadvantages, I'm just like to take the opportunity to try out JavaScript and node.js. Are there any files which have to be modified?

Here's the code I have for the script running on the server (only using it for trial purposes for now):

var http = require('http');

 http.createServer(function (req, res) {
      res.writeHead(200, {'Content-Type': 'text/plain'});
      res.end('Hello World\n');
  }).listen(1337);

I started the server (node fileName.js). However, When I try to access it with another client computer on the network, it doesn't seem to be working as the page doesn't seem to exist.

What is the procedure so that I can get Hello World outputed to my browser when I visit the server on port 1337?

Was it helpful?

Solution

Try to do it like this:

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, "your-adapter-ip"); // don't forget adapter IP

And then from the network point your browser to http://your-adapter-ip:1337.
Make sure that the firewall is open on that port.

OTHER TIPS

You should be able to browse to http://your_ubuntu_server_ip:1337 from the other client computer.

Can you reach the apache web server from the other computer? If so, you could stop apache, modify your code to use port 80, and try again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top