Deploying Express Server on Netlify with Lambda Functions

Hello there,
Adam here. I’m fairly new to Netlify but I have used it extensively for a load of static sites, and now I’m trying to deploy a web app made with node and express. I have looked extensively everywhere and have found multiple examples and forums on this subject “netlify with express” but none seem to detail my situation of having a few EJS Pages and a few template EJS pages. My issue might be later on to do with this situation but right now I’m having another issue that I can’t quite get my head around.

So I installed netlify-lambda with “npm i netlify-lambda --save” at the start and when I went about to use it I got a runtime error with “netlify-lambda: command not found” when trying to run serve. So I uninstalled netlify-lambda and installed it with a global flag and then tried it again and then it actually seemed to build my functions locally as I got no errors in the console however when I went to the URL specified where my functions were running on http://localhost:9000/.netlify/functions/serve-remote I got no joy and an “Internal Server Error”. So I decided to push it anyway to Github and then tried to deploy it on netlify and it failed with the error as before locally that “netlify-lambda: command not found” so I’m guessing the project/folder doesn’t have netlify-lambda installed on it at runtime which I don’t get because my build command states that “npm install” so I thought this would install all dependencies before trying to deploy and therefore the dependency would be accessible to the project to use.

I do believe I have the file structure of this all wrong for deploying but I’ve never deployed a web app before as I’m a novice on node and deploying full-stack web apps so some guidance on this would be appreciated greatly aswell.

Here is my GitHub to see my file structure: https://github.com/Adamoc14/CourtneyKingdomWebsite
and
Here’s my deployment log error
deploy https://app.netlify.com/sites/infallible-bardeen-aeb53e/deploys/5f1d9220b5e24913d5753cf5

Would be happy to provide any more resources or whatever is needed for anyone to help me.

Cheers,
Adam O’ Ceallaigh

Hey @adamoc and welcome to the forum :grinning:

netlify-lambda is great for local testing, but for deploying functions on Netlify, I’d recommend not using it. Our build system will automatically package your functions for you as long as you declare the name of the functions directory in the netlify.toml. In your case, your function is in the express directory, so that line of your netlify.toml would be:

functions="express"

instead of:

As for deploying, a few things:

  1. our build system will automatically npm install dependencies for you if there’s a package.json in the repo, which there is, so you can remove that bit from your build command
  2. since all you’re “building” is the function and nothing else, I think you can get away with your build command being just # as described here in our docs:
    https://docs.netlify.com/functions/configure-and-deploy/#configure-the-functions-folder

Want to give some of those suggestions a shot and let us know how it goes?

1 Like

Also! You may find this repo useful for trying things out and learning what’s possible with functions:

1 Like

Hi @jen ,
Thank you so much for your swift reply. I took all your pointers on board and as suggested issue seems to have resolved. I have marked your answer as the solution and will definitely check out the link your provided for further reading.
Thanks again and I will probably see you soon in another forum.
Adam

Yay, so glad to hear you’re up and running! :partying_face:

1 Like