Hi, thank you for the responses.
I am using express as a simple framework for organizing my API and using the package serverless-http to wrap the express app as a lambda function. Netlify actually has a very similar example posted (https://www.netlify.com/blog/2018/09/13/how-to-run-express.js-apps-with-netlify-functions/) I think the express part of my question was a bit of a red herring. I am more trying to figure out how to organize a project and its dependancies with both frontend and backend components.
@verythorough, after I posted this question I found the bit in the documentation you pointed out. The missing bit of information I needed that you pointed to was that unbundled dependancies are resolved from the nearest package.json and node_modules.
After fiddling around with Netlify Functions a fair bit and from your answers, I think the following statements are true:
- When Netlify pulls a project to build and deploy it, it runs a single build command from the base directory.
- Netlify Functions are deployed from the functions folder you specify. They have no build step.
- If the functions have dependancies (or are unbundled), the build bot will attempt to resolve them from the closest node_modules folder (e.g. ./node_modules, or …/node_modules, or …/…/node_modules, etc.). Again, the functions have no build step so the dependancies in package.json will not be installed automatically.
- If the project has multiple package.json files between the frontend and backend, they each need to be installed using the single build command. I haven’t seen a reference example yet for how to do this but surely some sort of build script could accomplish it.
Please let me know if I misunderstood anything.
At the moment, I merged the dependancies in the two package.json files I have into a single one that the build bot parses and installs. I’d rather not have all my dependancies together but this setup works for the moment. When I have some time, I’ll try to separate them out again and either have them all install in the single build step or try using lerna to manage the dependancies.
What would be helpful is way to easily install dependancies from multiple package.json.
Thanks for your help!