Netlify.toml and what exactly (functions = "functions") does

Hi! I just had a quick question. Right now I’m trying to run my app.js file through npm run start after having gotten down the netlify.toml file and code. npm run start runs fine and deploys the server correctly. However, as soon as i go to the localhost server it crashes and throws a bunch of errors. I think it has something to do with what exactly my code in netlify.toml is and also how my code is pulling that information but i’m not sure as i’m new to all this.
image

image

image

Hi @ethnwang

Welcome to the community!

Were you trying to override the default functions directory by using

[build]
     functions = "functions"

Looking at the second screenshot you provided above, it looks like your functions are located in the default directory. (YOUR_BASE_DIRECTORY/netlify/functions)

What happens if you remove

[build]
     functions = "functions"

from your netlify.toml?

That may not actually help with your root issue but it does seem like something you might need to try.

Thanks,

Elden

Hi thank you for your input! I have removed the contents of the toml file and the server doesn’t seem to be starting anymore. I inlcuded a screenshot of my package.json file cause i realized how i start it my be relevant. To be completely honest I don’t really know exactly what the code is doing since I am following a tutorial and that is what they said to do in the netlify.toml file. It just doesn’t seem to work so I am trying to figure out what is wrong myself.
image

There are 2 ways to define functions in Netlify:

  1. Place your files in netlify/functions directory - no config needed.
  2. Place your files in any different folder and add:
[functions]
  directory = "folder"

OR

[build]
  functions = "folder"

in your netlify.toml.

Since your functions exist in functions folder and not in netlify/functions folder, you need to add:

[functions]
  directory = "functions"

OR

[build]
   functions = "functions"

to your netlify.toml.


About the actual problem:

You do not need netlify-lambda anymore and rather, should be removing it immediately. It’s an old, and almost unmainted package which could be soon deprecated in the future.

Instead, if you use netlify-cli, it would handle the functions for you automatically.

Also, note that, Netlify is a static file host - if you’re only trying to run Express using Netlify Functions without having any website with us, that’s not allowed.