I have developed multiple event-driven cloud functions using NodeJS in GCP. Each cloud function has it's own package.json and index.js also there are many custom module (or utilities) file I created as part of each cloud functions.
But these custom modules are redundant across cloud functions i.e., they are repeated in every cloud function.
Now my question is, if I want to make an update/change in any one of the utility file then I must do the same change in all cloud functions individually. Also, what I observed is that package.json has many common dependencies but with different versions.
To avoid this, I am thinking to group these individual cloud functions into one with only one package.json and single copy of custom modules that can be referred by all cloud functions.
I tried my best to find some useful resource to implement this but couldn't find one.
I referred this document and here they mentioned that it's possible to have multiple function entry point (defined here)
Can anyone let me know how do I group multiple functions to one?
Current project structure:
Root-directory-
-dir_cloudFunction_A
-index.js
-myModule.js
-package.json
-dir_cloudFunction_B
-index.js
-myModule.js
-package.json
Currently I have two cloud functions under a root directory, cloud function A is in dir_cloudFunction_A directory and cloud function B is in dir_cloudFunction_B directory.
Each cloud function has index.js, myModule.js and a package.json
Now I have myModule.js (custom module) in each directory (same copy). Problem with this approach is that, when I need to make any changes in myModule.js, I must ensure that it is updated in all of it's copy wherever this has been referred.
To avoid this issue, I am suggested to share this myModule.js in one place and use it in 'n' number of cloud functions in root directory.
But I'm not sure how can I do this.
Related
Often I have code reused by multiple Netlify functions in the same project.
I know that anything within my /functions directory will become a function so I don't want to nest directories there. I could include it in /src, but if feels odd to comingle source with my single-page app (SPA) since they have different dependencies.
Is there a good convention for where to put this code? I can't seem to find any answer to this in any of Netlify's documentation.
I'm currently trying to create a testing environment for the cloud functions independently. I wanted to run the emulator within the functions folder, but there does not seem to be a way to use the root directory as functions directory.
Is there a proper way to change it?
If not, I would love to hear some suggestions on how to properly test the functions, when only the contents of the functions folder is available.
I currently have a firebase project with multiple cloud functions defined. Each of these functions resides in its own folder with two files: index.js and package.json. As far as I've been able to tell, it is possible to import all of these functions into the index.js file within the default functions folder and export them. However, this approach leads to the deployment of all the functions on the same instance. Is there a way to force them to deploy on their own instances? Thank you!
Firebase parses the index.js and creates separate containers for each exported function.
So each exported function in Cloud Functions runs on its own container instance(s) already. Separately exported functions will never run on the same container instance.
I am struggling to find the way to have 2 Azure functions in different language(C# and node.js) in Azure functions Project vs 2017.
Is there a way to do that?
Thanks!
Update
This method is invalid for v2 function(runtime ~2) because now it's required to use single language in one function app. See announcement.
So, the 2 project doesn't replace the functions created by first project?
Do you mean that you found some functions are replaced after new project being deployed to Azure?
Normally they won't be replaced unless functions in new project has same function names as ones already deployed.
create Azure Functions in 2 different language(C#, node.js) under one VS project
#Mikhail is right, VS doesn't provide ways for using js Azure function. No template and debug support for now.
But if you just want to run and deploy them together using VS, with no need to debug nodejs function, there's a workaround.
Generally speaking, you have to manually add nodejs function folder structure to VS project as below.
A folder named after your js function includes function.json and xxx.js file. If you have some packages installed by npm, also add package.json and node_modules folder.
function.json, xxx.js and package.json should be set as Copy if newer, so that they can be included in output dir like c# complied dll.
Not need to include node_modules locally, function host will locate them automatically. While after deploying to azure, you need to visit kudu(https://{functionappname}.scm.azurewebsites.net/DebugConsole). Execute npm install in console under wwwroot folder to install packages in package.json.
And some function templates if needed.
I'm currently developing a small game that will rely on a lot Azure App Functions to execute function from time to time. I followed a tutorial on MSDN (https://learn.microsoft.com/en-us/azure/azure-functions/functions-develop-vs#configure-the-project-for-local-development) explaining that I had to create a new project to host a function but so far, I already have 6 different functions and I don't really want to create 6 different projects.
Moreover, all these functions (developed in JavaScript) have a lot of code in common so I created a common JavaScript file with some helper function. Now that I have multiple projects, I can't use it anymore without copy/pasting it in all projects.
Finally, to be able to correctly develop the game, all the functions must be running in parallel on my development machine and I don't really want to open 6 (or more in the future) powershell instances to host these functions.
Is there a way to host multiple functions in the same project and deploy them easily on Azure ?
That's what Function Apps are for. Each Function App may contain multiple Functions, which will be deployed together.
You mention Javascript, but the linked tutorial is in C#. Regardless, you can put multiple functions into the same app: subfolders under the same root (where host.json file is), or static methods in the same C# project. Each function will have a separate function.json file. All functions can share the same code.