Created
August 23, 2025 08:37
-
-
Save diogoca/466c6afa183bc99b02c1b7532e5b35db to your computer and use it in GitHub Desktop.
Check if you're running in Edge Runtime vs Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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