20

I'm running a node.js server locally on port 9000 through Grunt. I also have a virtual machine running (vmware), but I can't access the node server through that. I've already configured the VM to access my Apache server on the host through localhost, but :9000 gives 'not found'.

Anyone know how to do this?

o01
  • 5,191
  • 10
  • 44
  • 85

2 Answers2

46

Got it! In my project's Grunt.js file there was this setting:

grunt.initConfig({
    ...
    connect: {
      options: {
        port: 9000,
        // Change this to '0.0.0.0' to access the server from outside.
        hostname: 'localhost'
      },
    }
    ...
  });

All I had to do was to change localhost to 0.0.0.0 and restart grunt server.

o01
  • 5,191
  • 10
  • 44
  • 85
  • 1
    I'm in a similar situation, but with this change, the page flashes up briefly in IE, then 404s.. I must be missing something! – ptim Jan 23 '14 at 01:47
  • Wasn't able to get this to work either (on a digital ocean droplet) – Kyle Pennell May 26 '14 at 19:14
  • works perfectly for me on VirtualBox using a NAT adapter for IE7, thanks! – Peadar Jul 30 '14 at 15:56
  • Thank you, thank you. I have tried every combination out there. On my Mac (the host machine), I had to use the IP address from system preferences (see @gyrostu's answer below). Other sources suggested the 10.211.55.2 style addresses - that didn't work for me. Type that IP address + port on the virtual machine and voila! – Ryan Wheale Oct 22 '14 at 15:37
  • Running into similar issue. What adapter setting are you using in VirtualBox? I've tried NAT as recommended above but didn't work. – tdc Apr 20 '15 at 20:20
3

You have to use your local IP address.

I am on a mac so I go to System Preferences > Network > "Advanced" tab > TCP/IP > IPv4 Address: (ex 10.0.0.3)

Then point your browser to that address using your port number (ex :9000) or whatever you have setup.

Ex: http://10.0.0.3:9000

I don't think this is very secure for your local box so make sure to kill the server when you are finished working. Hope this helps.

Ken
  • 207
  • 1
  • 11