如何访问使用app.set()在express js中设置的变量 [英] How to access variables set using app.set() in express js
本文介绍了如何访问使用app.set()在express js中设置的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用express的 app.set()
访问变量集,例如
How do i access the variables set using express's app.set()
for e.g
app.set('view engine','jade');
app.set('jsDirectory',/js/');
从指南中,我明白我可以使用 app.get(< key>)
,但这是 console.log(app.get('view engine'))的输出
。
From the guide, i understand that i can access the same using app.get(<key>)
, but this is the output of console.log(app.get('view engine'))
.
{ router:
{ app:
{ stack: [Object],
domain: null,
_events: [Object],
_maxListeners: 10,
_connections: 0,
connections: [Getter/Setter],
allowHalfOpen: true,
_handle: null,
httpAllowHalfOpen: false,
cache: {},
settings: [Object],
redirects: {},
isCallbacks: {},
_locals: [Object],
dynamicViewHelpers: {},
errorHandlers: [],
route: '/',
routes: [Circular],
router: [Getter],
root: 'C:\\Users\\Shahal\\Works\\App',
models: {},
extensions: {},
disconnectSchemas: [Function: disconnectSchemas],
passport: [Object] },
routes: {},
params: {},
_params: [],
middleware: [Function] } }
推荐答案
可通过app.settings对象获得:
They become available through the app.settings object:
app.set('oneSetting', 'one');
app.set('twoSetting', 'two');
app.set('view engine','jade');
console.log(app.settings.oneSetting);
console.log(app.settings.twoSetting);
console.log(app.settings['view engine']);
这篇关于如何访问使用app.set()在express js中设置的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文