Сначала вы установите функцию в вашем файле:
internalFunctions.js:
module.exports = {
HelloWorld: function test(event) {
console.log('hello world!');
}
};
Или, если вам не нравится много возиться с фигурными скобками:
module.exports.HelloWorld = function(event) {
console.log('hello world!');
}
module.exports.AnotherFunction = function(event) {
console.log('hello from another!');
}
Есть и другие стили, которые вы можете использовать: https://gist.github.com/kimmobrunfeldt/10848413
Затем в ваш файл index.js импортируйте файл как модуль:
const ifunctions = require('./internalFunctions');
И затем вы можете вызывать его напрямую в своих триггерах или HTTP-обработчиках:
ifunctions.HelloWorld();
Пример:
//Code to load modules
//...
const ifunctions = require('./internalFunctions');
exports.myTrigger = functions.database.ref('/myNode/{id}')
.onWrite((change, context) => {
//Some of your code...
ifunctions.HelloWorld();
//A bit more of code...
});