The generated code is hinting at a pattern that separates the production of the application configuration and consumers of that configuration. With the code left as you show, it maybe looks pointless to separate the roles when there is only 1 consumer, and more so when there is only 1 data value.
Think forward to when you have more configuration information. You may also want to read configuration from the command line and/or a file, and that configuration will likely need to be consumed by multiple modules. To share the configuration, you will split out a module just to produce the configuration data and likely use a library for command line and environment parsing (NCONF for example).
So you might have a file config.js which is the producer of all the configuration and contains all the logic to generate the data:
// config.js
var nconf = require('nconf');
nconf.env().argv(); // read from environment table, then command line
nconf.defaults({
'http': {'port': 3000},
'mode': 'devel'
});
module.exports = nconf;
The main app.js only contains code that consumes the data:
// app.js
var nconf = require('./config.js');
//no line app.set('port'...)
http.createServer(app).listen(nconf.get('http:port'),
function(){console.log('Server listening on port ' + nconf.get('http:port')}
);
This code sample is almost the exact same as app.set and app.get, but you might now say looks like a good pattern. I believe the code skeletons are hinting at the correct pattern: You should create and store the configuration in something all at one time and in one place, and then pull the data when later needed.
In other words, you don't want configuration logic scattered all through the code base. An example of the benefit can be shown by example. If I decided to read the configuration from a text file, my example above would change to:
nconf.env().file({file: 'appconfig.json'}).argv();
Nothing else changes.