我正在尝试像这样执行异步NodeJS v8.10.0和Express。
app.get('/settings', async function(req, res){
try {
const getTemperatureSettings = await getTemperatureSettings();
//...more await statements to be added.
res.render('settings', {
temperature_settings: getTemperatureSettings,
});
} catch (error) {
console.log('Error temperatureSettingRange', error);
}
});
function getTemperatureSettings() {
return new Promise(function (resolve, reject) {
couch.get(temperatureDb, "/_design/settings/_view/range?descending=true&limit=1").then(
function (data, headers, status) {
const temperatureSettingRange = data.data.rows[0].value;
resolve(temperatureSettingRange);
},
function (err) {
console.log('Could not get temperature settings', err);
}
);
});
}
但是,我得到以下错误。
Error temperatureSettingRange ReferenceError: getTemperatureSettings is not defined
尽管getTemperatureSettings()
在全局范围内,但似乎超出了范围-至少根据我的语法突出显示项,它没有被调用。
这是怎么了?