Develop and test a function locally
Run a function on your own machine with Azion CLI, send it real requests, and supply environment variables from a local file before you deploy.
You can run a function on your own machine with Azion CLI and send it real requests before deploying. The azion dev command starts a local development server for the current project. You read the response your code returns without deploying it first.
Prerequisites
- Azion CLI installed, and a personal token saved with
azion -t <your-token>. - A project on your machine. To create one, run
azion initand select the Javascript preset.
Run the function locally
azion dev builds the project and serves it from your machine. To start the server:
The command builds the project first, then prints the address it is serving on:
Use the address the command prints. To choose the port yourself, pass --port:
With the server running, send the function a request from another terminal:
The response your handler returns appears in the terminal. Anything the code writes with console.log() appears in the terminal running azion dev.
Provide environment variables locally
A function reads a variable with Azion.env.get(), which takes the key and returns the value:
The || 'Default value' fallback matters locally: Azion.env.get() returns undefined for a key that is not set. A handler that reads a variable directly into a response then returns the string undefined instead of failing. Give every variable a fallback, and the function runs before any variable exists.
Keep local values in a .env file next to the project, one KEY="value" pair per line:
azion deploy reads .edge/.env by default. To point it at a different file, pass --env:
Never commit a file that holds real credentials. Keep a .env.example with the keys and placeholder values in version control, and keep the real .env out of it.
Choose where to test a function
Three surfaces run a function before it serves production traffic, and they answer different questions.
| Surface | Where it runs | Reach for it when |
|---|---|---|
| Local development | Your machine, through azion dev | You are iterating on code, want real requests with your own headers and bodies, and want the edit-run loop to be fast |
| Preview deployment | Azion Console | You are working in the Console and want to read the response to one simulated request, built by PreviewProvider, without leaving the editor |
| Code editor | Azion Console | You are writing or correcting the code itself and want syntax highlighting and IntelliSense |
Local development is the only one of the three that accepts a request you compose yourself. It is where you exercise a handler across methods, headers, and bodies. Preview deployment sends one simulated request and renders the response.