NodeJS and MAMP running on local machine. Is it possible?

ぐ巨炮叔叔 提交于 2019-12-08 01:55:25

问题


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.


回答1:


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 ;)




回答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



来源:https://stackoverflow.com/questions/9739183/nodejs-and-mamp-running-on-local-machine-is-it-possible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!