Created
September 27, 2022 06:03
-
-
Save janaSunrise/98f406dec4e951aac24288397ba522a4 to your computer and use it in GitHub Desktop.
Check which Javascript runtime is being used (Browser, Node, Deno or Bun).
This file contains 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
function isNodeRuntime() { | |
// The reason we check for both `v8` instead of `node` is because when running `process.versions` under | |
// Bun, it returns `node` and `bun` version, but it doesn't use v8 engine, hence not a Node.js runtime. | |
return ( | |
typeof process !== 'undefined' && | |
process.versions && | |
process.versions.v8 | |
); | |
} | |
function isDenoRuntime() { | |
return typeof Deno !== 'undefined'; | |
} | |
function isBunRuntime() { | |
return typeof Bun !== 'undefined'; | |
} | |
function isBrowser() { | |
return typeof window !== 'undefined'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment