PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, January 8, 2022

[FIXED] Can't access the node.js web server inside a virtual machine

 January 08, 2022     lamp, localhost, node.js     No comments   

Issue

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.


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.



Answered By - Brad
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing