macos NodeJS 和 MAMP 在本地机器上运行。是否可以?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9739183/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NodeJS and MAMP running on local machine. Is it possible?
提问by ChrisMJ
Is it possible to have NodeJS and MAMP running together on the same machine? If so how would i achieve this?
是否可以在同一台机器上同时运行 NodeJS 和 MAMP?如果是这样,我将如何实现这一目标?
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。
采纳答案by Kerim Incedayi
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"
例如在主机中创建 node01.example.com。然后进入高级,在“自定义虚拟主机常规设置”中输入以下内容
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 并转到您的节点;)
回答by Mark Willis
This depends on what you want NodeJs to do?
这取决于您希望 NodeJs 做什么?
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