NodeJS: How to get the server's port?

后端 未结 19 1365
醉梦人生
醉梦人生 2020-12-02 05:47

You often see example hello world code for Node that creates an Http Server, starts listening on a port, then followed by something along the lines of:

conso         


        
相关标签:
19条回答
  • 2020-12-02 06:48

    I was asking myself this question too, then I came Express 4.x guide page to see this sample:

    var server = app.listen(3000, function() {
       console.log('Listening on port %d', server.address().port);
    });
    
    0 讨论(0)
提交回复
热议问题