Skip to content

Instantly share code, notes, and snippets.

@diogoca
Created August 23, 2025 08:37
Show Gist options
  • Select an option

  • Save diogoca/466c6afa183bc99b02c1b7532e5b35db to your computer and use it in GitHub Desktop.

Select an option

Save diogoca/466c6afa183bc99b02c1b7532e5b35db to your computer and use it in GitHub Desktop.
Check if you're running in Edge Runtime vs Node.js
export function getRuntimeEnvironment() {
// Check for Edge Runtime
if (typeof EdgeRuntime !== 'undefined') {
return 'edge';
}
// Check for Node.js
if (typeof process !== 'undefined' && process.versions?.node) {
return 'node';
}
// Check for Browser
if (typeof window !== 'undefined') {
return 'browser';
}
// Check for Deno
if (typeof Deno !== 'undefined') {
return 'deno';
}
// Check for Bun
if (typeof Bun !== 'undefined') {
return 'bun';
}
return 'unknown';
}
// Usage
console.log('Running in:', getRuntimeEnvironment());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment