4

Is it possible to have NodeJS and MAMP running together on the same machine? If so how would i achieve this?

Note: I can run them separately just not together. I assume its down to my NodeJS using the "localhost" as well as MAMP.

ChrisMJ
  • 1,620
  • 4
  • 21
  • 27

2 Answers2

6

You can setup Proxy and a host.

for example create node01.example.com in Hosts. Then Go to Advanced and enter the following in "Customized virtual host general settings"

ServerAlias node01.example.com

 <Location />

  ProxyPass http://127.0.0.1:3000/

ProxyPassReverse http://127.0.0.1:3000/

</Location>

when you visit node01.example.com you'd pass through MAMP and go to your node ;)

Kerim Incedayi
  • 645
  • 6
  • 11
  • I've added node01.example.com in my /etc/hosts and created a new Host as you mentioned above but it still goes to my PHP subdirectory and doesn't forward to :3000 . Any ideas? – neebz Jan 21 '13 at 15:39
  • you don't need to create any additional hosts in /etc/hosts. Just make sure there isn't any other Host under Mamp responding to the request. This is the exact code I'm using. – Kerim Incedayi Jan 22 '13 at 19:26
  • Any way of also sending headers with this? – im_benton Apr 24 '14 at 18:13
2

This depends on what you want NodeJs to do?

Are you using NodeJS to work as a webserver?

You could set it to run on another port number - this would let you access it through:

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

Then visit http://localhost:1337

Mark Willis
  • 1,711
  • 1
  • 14
  • 23