Struggling with typescript organization in my firebase functions. I'm fine keeping trigger functions in index.ts for now, but need help organizing other utility functions elsewhere.
Current index.ts setup:
import * as functions from 'firebase-functions';
import * as rp from "request-promise-native";
import * as admin from 'firebase-admin';
admin.initializeApp(functions.config().firebase)
async function func1(){
return 'blaw'
}
async function func2(){
return 'blaw2'
}
module.exports = func1
module.exports = func2
New index.ts import:
import { func1, func2 } from './commoncode'</p>
<p>Snippet from index.ts:</p>
<pre><code>export const on_plan_upgrade_request = functions.database.ref("plan_upgrades/{id}").onWrite(async (change, context) => {
console.log("start of on_feedback_received")
const rsp = await func1()
const rsp2 = await func2()
// Rest of the code...
});
Need to move func1() and func2() to a file named utility_code.ts. How should it be structured and referenced in index.ts?
UPDATE: Getting an error stating commoncode.ts is not a module.