Question

First off, I would like to say that I have searched and seem similar topics asking about issues with simple usages of nodejs, but all of those focus on "what's wrong with my nodejs code" whereas I know my nodejs works but my example doesn't. I'm looking for some experienced people to give me some suggestions as to why my examples wouldn't work.


I have recently set up a LAMP stack on a virtual ubuntu machine (using VMware Player) and installed nodejs. I have done a simple program to verify my installation, which works as expected:

nodejs_test.js:

console.log('Hello World');

Next, I tried a bigger example, found online:

var http = require('http');

var server = http.createServer(function(req, res) {
  res.writeHead(200);
  res.end('Hello Http');
});
server.listen(8080);

I have tried all of the following http://localhost:8080, http://127.0.0.1:8080, curl localhost:8080

With the two first (loaded in my desktop's Chrome browser) the request times out to the "oops" page. Running the curl method there is no output, but it is obvious that the issue is the same.

This is my first time taking a crack at web-dev, so feel free to assume the littlest of errors.

Was it helpful?

Solution

localhost/127.0.0.1 is the address of your machine, not your VM. If you want to go to your VM, you need to go to its IP address.

Alternatively, you can set up port forwarding so that your local ports forward to the ports on your VM.

OTHER TIPS

Replacing local host with your IP address will do the trick

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