I am a NodeJS newbie and have a really simple question.
I want to store the port of the server in the application configuration. I use something like this to store it in the app config:
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
// My configuration:
app.set('port', 80);
});
But how can I use the value of port? I cannot find an answer in the Express documentation.
Something like console.log('Port: ' + app.get('port'));
doesn't work (TypeError: Array.prototype.toString is not generic
).
Is there a better/other way to store a simple config value with the express framework?
Even simpler: app.set(setting)
with only one argument returns the value of setting
. This has the advantage of not using implementation-dependent features, and will work in 3.x.x as well
If you use Express 2.x.x then take a look at the definition of the function set(key, value): https://github.com/visionmedia/express/blob/2.5.11/lib/http.js#L436
Line 444: this.settings[setting] = val;
So this should works:
console.log(app.setting['port']);