I used express-generator for a new project.
In file bin/www exists the function normalizePort:
...
var http_port = 3000;
var port = normalizePort(process.env.PORT || http_port);
app.set('port', port);
...
// Normalize a port into a number, string, or false.
function normalizePort(val) {
var port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
return port;
}
return false;
}
Question:
Is really necessary the function or I can will simply?
app.set('port', parseInt(process.env.PORT, 10));
The function is generic and avoid possibles errors?
I use dotenv and dotenv-safe module for load my file .env