Serverless function limit

Hey guys

I’m evaluating the hobby plan and I’ve got a question about the automatic serverless node function support.

It seems anything I put in the top level /api directory will be treated as an individual serverless function. However, I’ve noticed that anything I put in there (for example a helper JS class or utility method) will be treated as a serverless function?

I’ve gotten the limit warning on my auto deployment for my project (12 serverless functions maximum). I’ve even noticed that even if I have a JS file file that’s entirely commented out, it still counts towards my limit.

Is this the expected behaviour? Is there a way I can include these JS files and not have them contribute to the limit? I’ve tried adding them to an _ folder like _utilities and even naming them _helper.js but nothing seems to work.

Any help on this would be great

Cheers

This is expected behavior, adding files to /api at the top level will bundle each into a serverless function as you deploy

You can import code from outside of /api, so moving your utility functions into /lib/or something would be the best way to avoid creating extra serverless functions while still using them

Alternatively, if you’re using Next.js then there is much more flexibility with the /app/api directory, which does support folders

Thanks for that, that all makes sense, I’ll try moving my shared utilities outside of the /api directory and giving it a go again.

Cheers!

1 Like