expressjs / generator

Express' application generator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

why do you need to store the port in express if you later set the port from var

ionutale opened this issue · comments

commented

app.set('port', port);

/**

  • Get port from environment and store in Express.
    */

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

/**

  • Create HTTP server.
    */

var server = http.createServer(app);

/**

  • Listen on provided port, on all network interfaces.
    */

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

please explain

It is stored in a variable as it is used in multiple places in the file.

As for storing in on express as a setting, it is not necessary, but a common convention to get the port in your other files with app.get('port')