Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access node.js/grunt server through localhost:port on virtual machine

Tags:

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?

like image 409
o01 Avatar asked Oct 25 '13 07:10

o01


People also ask

How do I access node server?

Here, the server listens to localhost on port 3000 and prints "Server running at http://127.0.0.1:3000/" in command prompt. Open a browser and enter url http://127.0.0.1:3000/. The browser will display Hello World message on the screen.


2 Answers

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.

like image 64
o01 Avatar answered Oct 22 '22 18:10

o01


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.

like image 32
Ken Avatar answered Oct 22 '22 18:10

Ken