Best way to detect if app is running on Netlify at runtime?

Hi everyone,

I’m looking for the most reliable way to check if my application is running on Netlify at runtime (not during build time).

I know about the build metadata environment variables like process.env.NETLIFY that are available during the build process, but I need to detect if an app is actually running on Netlify.

Here’s my current solution:

function isNetlifyRuntime(): boolean {
  if (typeof process === 'undefined' || !process.env) {
    return false;
  }

  return (
    Boolean(process.env.NETLIFY) ||
    Boolean(process.env.NETLIFY_FUNCTIONS_TOKEN) ||
    (typeof process.env.URL === 'string' && process.env.URL.endsWith('netlify.app'))
  );
}

Thanks for any guidance!

Hi there. You can check for the Netlify global: if (globalThis.Netlify).