尝试设置 Node.js Web 服务器
我是 Web 服务器和 node.js
的新手,我需要一些帮助。
我不知道要在 .listen(); 中放入什么
我认为因为我希望它连接到互联网,所以服务器需要监听端口 80,但我不知道该将什么作为第二个值。
.listen(80, "What do I add here?");
我还有一个免费域名(www.example.co.cc
),它指向动态 dns (DnsExit),因为我是动态 ip。我安装了更新我的 IP 地址所需的程序。
我有什么遗漏的吗?
I am new to web servers and node.js
and I need some help.
I have no idea what to put in the .listen();
I think since I want it to connect to the internet the server needs to listen to port 80 but but I don't know what to put as the second value.
.listen(80, "What do I add here?");
Also i have a free domain name (www.example.co.cc
) that is pointing to a dynamic dns (DnsExit) since I dynamic ip. I installed to program needed to update my ip address.
Is there anything I am missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您看过 Node.js 项目主页上的示例吗?
清楚地演示了
.listen( 1337, "127.0.0.1" );
然后下一行读取Server running at http://127.0.0.1:1337/
- 所以第二个参数是你想要监听的IP。如果您查看文档,您会发现第二个参数实际上是可选的,如果省略它,Node.js 将接受指向任何 IPv4 地址的传入连接。Have you seen the example on the homepage of the Node.js project?
It clearly demonstrated
.listen( 1337, "127.0.0.1" );
and then the next line readsServer running at http://127.0.0.1:1337/
- so the second argument is the IP you want to listen on. If you then take a look at the documentation you will see that this second argument is actually optional, if you omit it, Node.js will accept incoming connections directed at any IPv4 address.