Guide
Creating and Deploying a Netlify Function with Node.js
Learn how to create, test, and deploy a Netlify Function with Node.js, including a concrete code example, CLI commands, and the platform’s limits and typical pitfalls.
Published by Tasadduq Burney
16 Aug 2026, 17:08 UTC
2 min59.6K views0

Quick answer: add a handler file and push
To get a working Netlify Function, create a JavaScript file under netlify/functions/ that exports a handler, commit it, and push. Netlify automatically bundles the code and makes it available at /.netlify/functions/ on each deploy.
Worked example
Assume you have a Netlify‑linked site and the Netlify CLI installed.
- Create the functions folder (if it doesn’t exist):
Permission needed: write access to the repository.# run in the root of your repo mkdir -p netlify/functions - Add a simple handler (
netlify/functions/hello.js):
Key point: the exported// netlify/functions/hello.js exports.handler = async (event, context) => { return { statusCode: 200, body: JSON.stringify({ message: 'Hello from Netlify Functions' }) }; };handlerreceivesevent,context, and (if using callbacks) acallbackargument. - Commit and push:
Risk: pushing largegit add netlify/functions/hello.js git commit -m "Add hello function" git push origin mainnode_modulescan exceed the 250 MB function bundle limit and cause a deploy failure. - Verify locally before pushing (optional but recommended):
You should see the JSON response. If the command fails, ensure you have linked the site with# run in the repo root netlify dev # then open http://localhost:8888/.netlify/functions/hellonetlify linkand that the CLI version is ≥ 2.0. - After push, check the live endpoint:
Replacecurl https://YOUR_SITE.netlify.app/.netlify/functions/hello # Expected output: {"message":"Hello from Netlify Functions"}YOUR_SITEwith your actual subdomain or custom domain.
Limits and common mistakes
- Execution time: 10 seconds for regular functions (26 seconds for background functions). Long‑running loops or synchronous blocking code will cause a timeout.
- Payload size: request and response bodies are limited to 1 MB each. Sending larger data will be truncated or rejected with a 413 error.
- Concurrency: free tier allows up to 100 simultaneous invocations; higher tiers increase this limit. Exceeding concurrency results in 429 responses.
- Bundle size: the zipped function (including dependencies) must stay under 250 MB. Large native modules that aren’t compatible with the Amazon Linux execution image will fail at runtime.
- Environment variables: variables set in the Netlify UI are only available during deployed builds. To test them locally, run
netlify devafter defining them in the UI or a.envfile (the CLI automatically picks them up). - Forgotten export: if the file does not export a
handlerproperty, Netlify logs “Function hello.js missing handler” and returns a 502 error.
By following the steps above and checking the limits, you can reliably add serverless endpoints to a Netlify site without managing infrastructure.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.