私がここでやろうとしているのは、同じオブジェクトの関数内からcontext
プロパティ (context.settings
より具体的には ) にアクセスすることです。ready
これを行うための正しい構文が何であるかはわかりません。
コードは次のとおりです。
module.exports = {
context: {
settings: require('./settings')
},
listen: function(callback) {
listen(context.settings.http.port);
callback(null);
},
ready: function (err) {
if (err)
{
throw err;
}
console.log("Ready and listening at http://localhost:" + context.settings.http.port);
}
};
明確にするために、私は行を参照していますconsole.log("Ready and listening at http://localhost:" + context.settings.http.port);
編集:もう少し文脈(ha)
試してみthis.context.settings.http.port
ましたが、取得でき
TypeError: Cannot read property 'settings' of undefined
ます。
settings.js
念のため、 の内容は次のとおりです...
module.exports = {
db: {
host: '127.0.0.1',
port: 27017,
name: 'jsblogdemo'
},
http: {
port: 3000
}
};
ありがとう!