Javascript folders for sharing code between MongoDb Realm Functions?

Hi! My app is currently using Firebase Authentication and Firebase Functions. I will keep Auth, but am looking to migrate some cloud functions away from firebase and into MongoDb Realm.

In firebase, you are able to structure your code into folders so you can share code between multiple functions, which is nice and intuitive. In MongoDb Realm this doesn’t seem possible? Am I missing something? It looks like a folder is created for each MongoDb Realm function and you get config.json and a source.js, so how do I share code between functions?

The only way I have seen mentioned is by creating your own npm modules, which seems a bit complex. Is this the only way?

Hey Simon - you should be able to call one function from another function as described here: https://docs.mongodb.com/realm/functions/call-a-function#call-from-another-function . Does that help in your case?

Although we only provide one folder with all function source code, we are currently in the process of introducing folders to structure functions.

1 Like

Thanks, this is how I structure code today when testing MongoDb… but it definitely is not a great development experience compared to what I am being used to with firebase, where you can structure code in any way you like and are able to use npm dependencies directly without manually uploading like in MongoDb Realm.

It is great that you are working on this! When folders are in place I will be a lot more comfortable migrating my firebase code to MongoDb :wink: