This feature is in
The Edge Functions beta is enabled by default for all accounts. To try the feature, add edge functions code to your site.
# Create an edge function
Each edge function has two required parts:
- A function file with logic for modifying requests and responses
- A declaration associating a path on your site with a function to execute on requests to that path
Create a function file at
netlify/edge-functions/hello.jswith the content below:
export default () => new Response("Hello world");
The edge functions directory
netlify/edge-functionsis relative to your site’s base directory.
helloedge function for the
/testroute by adding the following to
[[edge_functions]] path = "/test" function = "hello"
# Test locally
You can use Netlify CLI to test edge functions locally before deploying them to Netlify.
Ensure you have the latest version of Netlify CLI installed:
npm install netlify-cli -g
Launch Netlify Dev to start a development environment that executes edge functions on local requests:
Visit localhost:8888/test to execute the
helloedge function declared for the
Changes to edge functions are applied on new requests.
hello.jsto change the
export default () => new Response("Updated hello!");
Save your updated function file.
Reload localhost:8888/test and note that the response has changed.
To debug edge functions locally, launch Netlify Dev with the
edgeInspectBrk flag. For details, visit the CLI docs.
By default, the
geo location used is the location of your local environment. To override this to a default mock location of San Francisco, CA, USA, use the
--geo=mock flag. To mock a specific country, use
--geo=mock --country= with a two-letter country code. For more information about the
--geo flag, visit the CLI docs.
Invoke the deployed production version of your
hello edge function declared for the
/test route by accessing
Deploys of edge functions are atomic. This means that when a new deploy includes changes to function logic or declarations, the behavior of edge functions in old deploys won’t be impacted. Updates to edge functions move to production only when you publish a new production deploy.
To access logs for your production edge functions:
- In the Netlify UI, visit your site’s Edge Functions tab.
To access logs for other versions of your edge functions:
- In the Netlify UI, go to your site’s Deploys tab.
- Find the deploy of interest.
- Follow the Edge Functions link in the deploy detail page header.
In both cases, Netlify provides a running log for the last 24 hours of activity, including:
- Timestamp of each invocation
- Any console statements included in your edge function code
Did you find this doc useful?
Your feedback helps us improve our docs.