Netlify: How to use environment variables in Netlify functions

Join the AI Workshop to learn more about AI and how it can be applied to web development. Next cohort February 1st, 2026

The AI-first Web Development BOOTCAMP cohort starts February 24th, 2026. 10 weeks of intensive training and hands-on projects.


To use environment variables in your Netlify Functions, access the process.env variable:

process.env.YOUR_VARIABLE

You can use object destructuring at the beginning of your JS file, to make the code nicer:

const { YOUR_VARIABLE } = process.env;

so you can just use YOUR_VARIABLE in the rest of the program.

You set the variables through the Netlify administration interface (you can also add them in your repo, but I’d recommend using the Netlify UI so you have no secrets in your Git repository).

Note: this does not work on Netlify Edge Functions, just on Netlify “regular” Functions that run on AWS Lambda.

For Netlify Edge Functions, you need to use Deno.env.get(), like this:

Deno.env.get('YOUR_VARIABLE')

Example:

export default () => new Response(Deno.env.get('YOUR_VARIABLE'))

Lessons in this unit:

0: Introduction
1: Create a Netlify account
2: Deploy to Netlify
3: A tutorial to host your Static Site on Netlify
4: Auto trigger deploys on Netlify
5: Netlify Lambda Functions Tutorial
6: ▶︎ How to use environment variables in Netlify functions
7: How to use npm packages in Netlify Functions
8: How to access query parameters in Netlify functions
9: How to test Netlify Functions locally
10: How to use Netlify Edge Functions
11: How to set up "cloud cron jobs" using Netlify Scheduled Functions
12: How I fixed the trailing slash in Netlify rewrites
13: Durable cache on Netlify
14: How to return HTML from a Netlify function
15: How to use ES modules in Netlify functions
16: How to trigger a Netlify-Vercel-Cloudflare Pages redeploy using a link