【发布时间】:2011-06-17 23:21:31
【问题描述】:
你经常会看到 Node 的示例 hello world 代码,它创建一个 Http 服务器,开始监听一个端口,然后是类似以下内容的代码:
console.log('Server is listening on port 8000');
但理想情况下你会想要这个:
console.log('Server is listening on port ' + server.port);
如何在调用 server.listen() 之前检索服务器当前正在侦听的端口而不将数字存储在变量中?
我以前见过这样做,但我在 Node 文档中找不到它。也许这是要表达的特定内容?
【问题讨论】:
-
在
req.headers.host中查找
标签: javascript node.js express port