// ===============================================================================
// Auth
// ===============================================================================
const admin = require('firebase-admin'); //what happens if i move this line
admin.initializeApp(); //and this line
module.exports = function(app) {
//to this line
//and this line?
app.post('/login',function(req,res) {
const token = req.body.token;
console.log('token sent: ' + token);
admin
.auth()
.verifyIdToken(token)
.then(result => {
console.log('verifyIdToken result: ' + result);
});
res.send({ valid: 'havent programmed this yet' });
});
};
假设我正在使用上面的代码。我很好奇为什么放置第一行代码后它仍然可以运行:
const admin = require('firebase-admin');
admin.initializeApp();
是从module.export到其内部的匿名函数的外部吗?我感到很困惑!此函数是否在其模块外部查找以获取此范围,并且从module.exports而不是外部声明此const const有什么区别?