javascript - app.set('port', 8080) versus app.listen(8080) in Express.js

后端 未结 3 1546
半阙折子戏
半阙折子戏 2021-02-04 02:20

I\'ve been trying to use Express.js to launch a website. At first, I was using app.set(\'port\', 8080) but the browser was unable to connect to the page. Afterwards

3条回答
  •  难免孤独
    2021-02-04 03:04

    It is simple enough to declare a variable server at the bottom of the page and define the port that you want. You can console.log the port so that it will be visible in the command line.

    var server = app.listen(8080,function(){
       console.log('express server listening on port ' + server.address().port);
        })
    

提交回复
热议问题