Use Netlify's predefined environment variables in Netlify functions

Hi, in a Next.js Site (with Essential Next.js Plugin) I struggle to use Netlify’s predefined environment variables (Build and Git metadata, e.g. REPOSITORY_URL) in API routes. I can use the env variables i have set by myself, but not the predefined env variables (which i can use in the rest of my app). Is this behaviour intended? thanks

Hi @felixboet

Welcome to the Netlify community.

Have a look at this Support Guide. Might have answers you are looking for

1 Like

You can definitely use the pre-defined variables. To check all the ones that are available, you could try console.log(process.env) and you’d get the name an value of all available variables in your functions’ console. You could see if the one you’re looking for actually exists there or not.

Thanks @hrishikesh and @coelmay ! Maybe i am doing something wrong there, but i just get the following predefined environment variables in my functions console: NETLIFY_IMAGES_CDN_DOMAIN
SITE_ID, PWD, LANG, URL, SHLVL, SITE_NAME + the aws stuff, some function specific vars and my own vars. I don’t get NETLIFY, BRANCH, CONTEXT, REPOSITORY_URL etc.

Any idea?

netlify-plugin-inline-functions-env - npm This plugin might help you.


Thank you! That works great. :slight_smile: Is there a reason why these vars are not exposed to Netlify functions?

Yes, AWS has a 4 KB limit of environment variables’ total size. While most people are able to manage within that, some of them are not. So, Netlify keeps minimum variables available by default and those who want them, can later get it this way.