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

后端 未结 3 1553
半阙折子戏
半阙折子戏 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

    For example:

    var port = 8080
    app.listen(port);
    console.log(`Listening on port ${port}`);
    

    Line by Line Explaination:

    var port = 8080; =>Creates a variable(everything in javascript is an object) and sets the port location to localhost 8080 app.listen(port); =>The application made using express module checks for any connections available and if yes then it connects and the application launches console.log('Listening on port ' + port); =>Displays the message onto the terminal once deployed successfully

提交回复
热议问题