0

I am using Node.js to upload a Typescript file(index.ts) with Cloud functions. I now have a Firestore trigger written in external JavaScript file(notifyNewMessage.js), which I would like to somehow declare in the Typescript file.

Both files are in the same directory:

enter image description here


index.ts:

import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'

//declare javascript file here???

export const cloudFunction= functions
  .firestore.document(`Users/{user_id}`).onWrite(async (change, _context) => {

   //Function code....

}


notifyNewMessage.js

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

exports.notifyNewMessage = functions.firestore{
   //Cloud function I want to declare in index.ts
}

It would be great if anyone can provide a way for me to do this, or point me in a direction where I can learn how, as Typescript and JavaScript are not my strong points :)

Thanks in advance!

1 Answer 1

1

Assuming you are trying to import an exported function from the js file. Wouldn't it be something simple as one of the following:

import notifyNewMessage from "./notifyNewMessage";

OR

import { notifyNewMessage } from "./notifyNewMessage";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.