Overview
Pages Functions is a Serverless architecture solution that allows you to run server-side code without configuration or managing servers. It automatically scales based on website access traffic and provides stronger concurrency capability through EdgeOne global edge nodes. You can use Functions to deploy APIs and connect multiple databases, helping you achieve better integration of front-end and back-end projects and deployment.
At deployment time, Pages automatically identifies the project framework and optimizes configurations, enabling intelligent routing and low-latency access based on the EdgeOne edge network. Currently, two types of Functions are available.
Cloud Functions provide multiple runtime environments, each with its own libraries, APIs, and features. They each have their own strengths and weaknesses.
Node.js runtime is now supported, with full compatibility, native module support, and long calculation time, suitable for business scenarios deeply dependent on the Node.js ecosystem.
Edge Functions rely on global edge nodes, provide ultra-low latency and millisecond-level cold startup, and are suitable for high-concurrency, delay-sensitive business.
Note:
If you need to use Next.js specific grammar or framework context APIs, it is advisable to develop in the built-in API routing directory of Next.js. Pages will handle deployment automatically.
Quick Start
Cloud Functions takes Node Functions as an example. Under the `./node-functions/api` directory of the project, use the following example code to create your first Node Functions:
export default function onRequest(context) {return new Response('Hello from Node Functions!');}
or through a Template to deploy application deployment of the Edge Functions project.
Under the directory ./edge-functions/api, use the following example code to create your first Edge Functions:
export default function onRequest(context) {return new Response('Hello from Edge Functions!');}
or through a Template to deploy application deployment of the Edge Functions project.
Difference between Cloud Functions and Edge Functions
Features | Cloud Functions | Edge Functions |
the location of running | Cloud Central | global edge node |
Cold Startup Duration | relatively long | millisecond-level |
latency performance | Moderately Low | extremely low |
runtime environment | Multiple Runtime environments (Node.js Runtime is now supported) | Edge Runtime |
Scenarios | complex data processing relatively long execution time | high-concurrency, latency-sensitive short execution time |
