简体   繁体   English

在本地计算机上运行的NodeJS和MAMP。 可能吗?

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

Is it possible to have NodeJS and MAMP running together on the same machine? 是否可以在同一台计算机上同时运行NodeJS和MAMP? 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. 我假定它使用“ localhost”以及MAMP归结到我的NodeJS。

You can setup Proxy and a host. 您可以设置代理和主机。

for example create node01.example.com in Hosts. 例如,在主机中创建node01.example.com。 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 ;) 当您访问node01.example.com时,您将通过MAMP并转到您的节点;)

This depends on what you want NodeJs to do? 这取决于您希望NodeJ做什么?

Are you using NodeJS to work as a webserver? 您是否正在使用NodeJS充当网络服务器?

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 然后访问http:// localhost:1337

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM