Menu

One editor, three runtimes: Bun, Browser, and the one in between
📰

One editor, three runtimes: Bun, Browser, and the one in between

DEV Community: typescript·JSLab·1 day ago
#4fyBt9sK
#devtotypescript#devto#dev#node#browser
Reading 0:00
15s threshold

Here are five lines of JavaScript:

" document " in globalThis ; " Bun " in globalThis ; globalThis . process ?. versions ?. bun ?? " not Bun " ;

import { readdir } from " node:fs/promises " ; ( await readdir ( " . " )). length ;

Enter fullscreen mode

Exit fullscreen mode

What do they print?

It depends on where they run. Run them in Bun and there's no document , there is a Bun , and readdir counts your files. Run them in a browser and document is there, Bun isn't, and that node:fs import doesn't make it past the build.

Most of us switch between those worlds all day. This post is about turning that into one switch per tab, in JSLab . It's our own tool, so discount the praise accordingly. The snippet above comes straight from the runtime docs .

Three runtimes, one menu

Each JSLab tab runs its code in one of three runtimes.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.